lib/operations/collection_ops.js
function count(coll, query, options, callback) {
  if (typeof options === 'function') (callback = options), (options = {});
  options = Object.assign({}, options);
  options.collectionName = coll.s.name;

  options.readPreference = resolveReadPreference(options, {
    db: coll.s.db,
    collection: coll
  });

  let cmd;
  try {
    cmd = buildCountCommand(coll, query, options);
  } catch (err) {
    return callback(err);
  }

  executeCommand(coll.s.db, cmd, options, (err, result) => {
    if (err) return handleCallback(callback, err);
    handleCallback(callback, null, result.n);
  });
}
function count(coll, query, options, callback) {
  if (typeof options === 'function') (callback = options), (options = {});
  options = Object.assign({}, options);
  options.collectionName = coll.s.name;

  options.readPreference = resolveReadPreference(options, {
    db: coll.s.db,
    collection: coll
  });

  let cmd;
  try {
    cmd = buildCountCommand(coll, query, options);
  } catch (err) {
    return callback(err);
  }

  executeCommand(coll.s.db, cmd, options, (err, result) => {
    if (err) return handleCallback(callback, err);
    handleCallback(callback, null, result.n);
  });
}
function count ( coll , query , options , callback ) { if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ; options = Object . assign ( { } , options ) ; options . collectionName = coll . s . name ; options . readPreference = resolveReadPreference ( options , { db : coll . s . db , collection : coll } ) ; let cmd ; try { cmd = buildCountCommand ( coll , query , options ) ; } catch ( err ) { return callback ( err ) ; } executeCommand ( coll . s . db , cmd , options , ( err , result ) => { if ( err ) return handleCallback ( callback , err ) ; handleCallback ( callback , null , result . n ) ; } ) ; }
Count the number of documents in the collection that match the query.

@method
@param {Collection} a Collection instance.
@param {object} query The query for the count.
@param {object} [options] Optional settings. See Collection.prototype.count for a list of options.
@param {Collection~countCallback} [callback] The command result callback
Count the number of documents in the collection that match the query .