@@ -2773,7 +2773,7 @@ Query.prototype.estimatedDocumentCount = function(options) {
27732773 this . op = 'estimatedDocumentCount' ;
27742774 this . _validateOp ( ) ;
27752775
2776- if ( typeof options === 'object' && options != null ) {
2776+ if ( options != null ) {
27772777 this . setOptions ( options ) ;
27782778 }
27792779
@@ -2832,7 +2832,7 @@ Query.prototype.countDocuments = function(conditions, options) {
28322832 this . merge ( conditions ) ;
28332833 }
28342834
2835- if ( typeof options === 'object' && options != null ) {
2835+ if ( options != null ) {
28362836 this . setOptions ( options ) ;
28372837 }
28382838
@@ -2870,21 +2870,24 @@ Query.prototype.__distinct = async function __distinct() {
28702870 *
28712871 * #### Example:
28722872 *
2873+ * distinct(field, conditions, options)
28732874 * distinct(field, conditions)
28742875 * distinct(field)
28752876 * distinct()
28762877 *
28772878 * @param {String } [field]
28782879 * @param {Object|Query } [filter]
2880+ * @param {Object } [options]
28792881 * @return {Query } this
28802882 * @see distinct https://www.mongodb.com/docs/manual/reference/method/db.collection.distinct/
28812883 * @api public
28822884 */
28832885
2884- Query . prototype . distinct = function ( field , conditions ) {
2886+ Query . prototype . distinct = function ( field , conditions , options ) {
28852887 if ( typeof field === 'function' ||
28862888 typeof conditions === 'function' ||
2887- typeof arguments [ 2 ] === 'function' ) {
2889+ typeof options === 'function' ||
2890+ typeof arguments [ 3 ] === 'function' ) {
28882891 throw new MongooseError ( 'Query.prototype.distinct() no longer accepts a callback' ) ;
28892892 }
28902893
@@ -2903,6 +2906,10 @@ Query.prototype.distinct = function(field, conditions) {
29032906 this . _distinct = field ;
29042907 }
29052908
2909+ if ( options != null ) {
2910+ this . setOptions ( options ) ;
2911+ }
2912+
29062913 return this ;
29072914} ;
29082915
0 commit comments