docs: function(dbOrUri, stream, callback) {
      if (arguments.length === 2) {
        callback = stream;
        stream = undefined;
      }
      if (!stream) {
        stream = process.stdout;
      }
      var db;
      var out = stream;
      var endOfCollection = crypto.pseudoRandomBytes(8).toString('base64');
      write({
        type: 'mongo-dump-stream',
        version: '2',
        endOfCollection: endOfCollection
      });
      return async.series({
        connect: function(callback) {
          if (typeof(dbOrUri) !== 'string') {
            // Already a mongodb connection
            db = dbOrUri;
            return setImmediate(callback);
          }
          return mongodb.MongoClient.connect(dbOrUri, function(err, _db) {
            if (err) {
              return callback(err);
            }
            db = _db;
            return callback(null);
          });
        },
        getCollections: function(callback) {
          return db.collections(function(err, _collections) {
            if (err) {
              return callback(err);
            }
            collections = _collections;
            return callback(null);
          });
        },
        dumpCollections: function(callback) {
          return async.eachSeries(collections, function(collection, callback) {
            if (collection.collectionName.match(/^system\./)) {
              return setImmediate(callback);
            }
            return async.series({
              getIndexes: function(callback) {
                return collection.indexInformation({ full: true }, function(err, info) {
                  if (err) {
                    return callback(err);
                  }
                  write({
                    type: 'collection',
                    name: collection.collectionName,
                    indexes: info
                  });
                  return callback(null);
                });
              },
              getDocuments: function(callback) {
                var cursor = collection.find({}, { raw: true });
                iterate();
                function iterate() {
                  return cursor.nextObject(function(err, item) {
                    if (err) {
                      return callback(err);
                    }
                    if (!item) {
                      write({
                        // Ensures we don't confuse this with
                        // a legitimate database object
                        endOfCollection: endOfCollection
                      });
                      return callback(null);
                    }
                    // v2: just a series of actual data documents
                    out.write(item);
  
                    // If we didn't have the raw BSON document,
                    // we could do this instead, but it would be very slow
                    // write({
                    //   type: 'document',
                    //   document: item
                    // });
  
                    return setImmediate(iterate);
                  });
                }
              },
            }, callback);
          }, callback);
        },
        endDatabase: function(callback) {
          write({
            type: 'endDatabase'
          }, callback);
        }
      }, function(err) {
        if (err) {
          return callback(err);
        }
        return callback(null);
      });
      function write(o, callback) {
        out.write(BSON.serialize(o, false, true, false), callback);
      }
    }