lib/operations/collection_ops.js
function distinct(coll, key, query, options, callback) {
  // maxTimeMS option
  const maxTimeMS = options.maxTimeMS;

  // Distinct command
  const cmd = {
    distinct: coll.s.name,
    key: key,
    query: query
  };

  options = Object.assign({}, options);
  // Ensure we have the right read preference inheritance
  options.readPreference = resolveReadPreference(options, { db: coll.s.db, collection: coll });

  // Add maxTimeMS if defined
  if (typeof maxTimeMS === 'number') cmd.maxTimeMS = maxTimeMS;

  // Do we have a readConcern specified
  decorateWithReadConcern(cmd, coll, options);

  // Have we specified collation
  try {
    decorateWithCollation(cmd, coll, options);
  } catch (err) {
    return callback(err, null);
  }

  // Execute the command
  executeCommand(coll.s.db, cmd, options, (err, result) => {
    if (err) return handleCallback(callback, err);
    handleCallback(callback, null, result.values);
  });
}
function distinct(coll, key, query, options, callback) {
  // maxTimeMS option
  const maxTimeMS = options.maxTimeMS;

  // Distinct command
  const cmd = {
    distinct: coll.s.name,
    key: key,
    query: query
  };

  options = Object.assign({}, options);
  // Ensure we have the right read preference inheritance
  options.readPreference = resolveReadPreference(options, { db: coll.s.db, collection: coll });

  // Add maxTimeMS if defined
  if (typeof maxTimeMS === 'number') cmd.maxTimeMS = maxTimeMS;

  // Do we have a readConcern specified
  decorateWithReadConcern(cmd, coll, options);

  // Have we specified collation
  try {
    decorateWithCollation(cmd, coll, options);
  } catch (err) {
    return callback(err, null);
  }

  // Execute the command
  executeCommand(coll.s.db, cmd, options, (err, result) => {
    if (err) return handleCallback(callback, err);
    handleCallback(callback, null, result.values);
  });
}
function distinct ( coll , key , query , options , callback ) { // maxTimeMS option const maxTimeMS = options . maxTimeMS ; // Distinct command const cmd = { distinct : coll . s . name , key : key , query : query } ; options = Object . assign ( { } , options ) ; // Ensure we have the right read preference inheritance options . readPreference = resolveReadPreference ( options , { db : coll . s . db , collection : coll } ) ; // Add maxTimeMS if defined if ( typeof maxTimeMS === 'number' ) cmd . maxTimeMS = maxTimeMS ; // Do we have a readConcern specified decorateWithReadConcern ( cmd , coll , options ) ; // Have we specified collation try { decorateWithCollation ( cmd , coll , options ) ; } catch ( err ) { return callback ( err , null ) ; } // Execute the command executeCommand ( coll . s . db , cmd , options , ( err , result ) => { if ( err ) return handleCallback ( callback , err ) ; handleCallback ( callback , null , result . values ) ; } ) ; }
Return a list of distinct values for the given key across a collection.

@method
@param {Collection} a Collection instance.
@param {string} key Field of the document to find distinct values for.
@param {object} query The query for filtering the set of documents to which we apply the distinct filter.
@param {object} [options] Optional settings. See Collection.prototype.distinct for a list of options.
@param {Collection~resultCallback} [callback] The command result callback
Return a list of distinct values for the given key across a collection .