@@ -1943,47 +1943,80 @@ Query.prototype._findOne = async function _findOne() {
19431943} ;
19441944
19451945/**
1946- * Exectues the query as a count () operation.
1946+ * Executes the query as a countDocuments () operation.
19471947 *
19481948 * #### Example:
19491949 *
1950- * query.count ().where('color', 'black').exec();
1950+ * query.countDocuments ().where('color', 'black').exec();
19511951 *
1952- * query.count ({ color: 'black' })
1952+ * query.countDocuments ({ color: 'black' })
19531953 *
1954- * await query.count ({ color: 'black' });
1954+ * await query.countDocuments ({ color: 'black' });
19551955 *
1956- * const doc = await query.where('color', 'black').count ();
1956+ * const count = await query.where('color', 'black').countDocuments ();
19571957 * console.log('there are %d kittens', count);
19581958 *
1959- * @param {Object } [criteria ] mongodb selector
1959+ * @param {Object } [filter ] mongodb selector
19601960 * @return {Query } this
1961- * @see mongodb http://www.mongodb.org/display/DOCS/Aggregation#Aggregation-Count
19621961 * @api public
19631962 */
19641963
1965- Query . prototype . count = function ( criteria ) {
1966- this . op = 'count ' ;
1964+ Query . prototype . countDocuments = function ( filter ) {
1965+ this . op = 'countDocuments ' ;
19671966 this . _validate ( ) ;
19681967
1969- if ( Query . canMerge ( criteria ) ) {
1970- this . merge ( criteria ) ;
1968+ if ( Query . canMerge ( filter ) ) {
1969+ this . merge ( filter ) ;
19711970 }
19721971
19731972 return this ;
19741973} ;
19751974
1975+ /**
1976+ * Executes a `countDocuments` Query
1977+ * @returns the results
1978+ */
1979+ Query . prototype . _countDocuments = async function _countDocuments ( ) {
1980+ const conds = this . _conditions ,
1981+ options = this . _optionsForExec ( ) ;
1982+
1983+ debug ( 'countDocuments' , this . _collection . collectionName , conds , options ) ;
1984+
1985+ return this . _collection . countDocuments ( conds , options ) ;
1986+ } ;
1987+
1988+ /**
1989+ * Executes the query as a estimatedDocumentCount() operation.
1990+ *
1991+ * #### Example:
1992+ *
1993+ * query.estimatedDocumentCount();
1994+ *
1995+ * const count = await query.estimatedDocumentCount();
1996+ * console.log('there are %d kittens', count);
1997+ *
1998+ * @return {Query } this
1999+ * @api public
2000+ */
2001+
2002+ Query . prototype . estimatedDocumentCount = function ( ) {
2003+ this . op = 'estimatedDocumentCount' ;
2004+ this . _validate ( ) ;
2005+
2006+ return this ;
2007+ } ;
2008+
19762009/**
19772010 * Executes a `count` Query
19782011 * @returns the results
19792012 */
1980- Query . prototype . _count = async function _count ( ) {
2013+ Query . prototype . _estimatedDocumentCount = async function _estimatedDocumentCount ( ) {
19812014 const conds = this . _conditions ,
19822015 options = this . _optionsForExec ( ) ;
19832016
1984- debug ( 'count ' , this . _collection . collectionName , conds , options ) ;
2017+ debug ( 'estimatedDocumentCount ' , this . _collection . collectionName , conds , options ) ;
19852018
1986- return this . _collection . count ( conds , options ) ;
2019+ return this . _collection . estimatedDocumentCount ( conds , options ) ;
19872020} ;
19882021
19892022/**
@@ -2329,7 +2362,7 @@ Query.prototype._findOneAndUpdate = async function() {
23292362} ;
23302363
23312364/**
2332- * Issues a mongodb [findAndModify](http://www.mongodb.org/display/DOCS/findAndModify+Command) remove command .
2365+ * Issues a mongodb findOneAndDelete .
23332366 *
23342367 * Finds a matching document, removes it, returning the found document (if any).
23352368 *
@@ -2339,28 +2372,25 @@ Query.prototype._findOneAndUpdate = async function() {
23392372 *
23402373 * #### Examples:
23412374 *
2342- * await A.where().findOneAndRemove(conditions, options) // executes
2343- * A.where().findOneAndRemove(conditions, options) // return Query
2344- * await A.where().findOneAndRemove(conditions) // executes
2345- * A.where().findOneAndRemove(conditions) // returns Query
2346- * await A.where().findOneAndRemove() // executes
2347- * A.where().findOneAndRemove() // returns Query
2348- * A.where().findOneAndDelete() // alias of .findOneAndRemove()
2375+ * await A.where().findOneAndDelete(conditions, options) // executes
2376+ * A.where().findOneAndDelete(conditions, options) // return Query
2377+ * await A.where().findOneAndDelete(conditions) // executes
2378+ * A.where().findOneAndDelete(conditions) // returns Query
2379+ * await A.where().findOneAndDelete() // executes
2380+ * A.where().findOneAndDelete() // returns Query
23492381 *
2350- * @param {Object } [conditions ]
2382+ * @param {Object } [filter ]
23512383 * @param {Object } [options]
23522384 * @return {Query } this
2353- * @see mongodb http://www.mongodb.org/display/DOCS/findAndModify+Command
23542385 * @api public
23552386 */
23562387
2357- Query . prototype . findOneAndRemove = Query . prototype . findOneAndDelete = function ( conditions , options ) {
2358- this . op = 'findOneAndRemove ' ;
2388+ Query . prototype . findOneAndDelete = function ( filter , options ) {
2389+ this . op = 'findOneAndDelete ' ;
23592390 this . _validate ( ) ;
23602391
2361- // apply conditions
2362- if ( Query . canMerge ( conditions ) ) {
2363- this . merge ( conditions ) ;
2392+ if ( Query . canMerge ( filter ) ) {
2393+ this . merge ( filter ) ;
23642394 }
23652395
23662396 // apply options
@@ -2373,7 +2403,7 @@ Query.prototype.findOneAndRemove = Query.prototype.findOneAndDelete = function(c
23732403 * Executes a `findOneAndRemove` Query
23742404 * @returns the results
23752405 */
2376- Query . prototype . _findOneAndRemove = async function ( ) {
2406+ Query . prototype . _findOneAndDelete = async function ( ) {
23772407 const options = this . _optionsForExec ( ) ;
23782408 const conds = this . _conditions ;
23792409
0 commit comments