@@ -1937,45 +1937,75 @@ Query.prototype._findOne = async function _findOne() {
19371937} ;
19381938
19391939/**
1940- * Exectues the query as a count () operation.
1940+ * Executes the query as a countDocuments () operation.
19411941 *
19421942 * #### Example:
19431943 *
1944- * query.count ().where('color', 'black').exec();
1944+ * query.countDocuments ().where('color', 'black').exec();
19451945 *
1946- * query.count ({ color: 'black' })
1946+ * query.countDocuments ({ color: 'black' })
19471947 *
1948- * await query.count ({ color: 'black' });
1948+ * await query.countDocuments ({ color: 'black' });
19491949 *
1950- * const doc = await query.where('color', 'black').count ();
1950+ * const count = await query.where('color', 'black').countDocuments ();
19511951 * console.log('there are %d kittens', count);
19521952 *
1953- * @param {Object } [criteria ] mongodb selector
1953+ * @param {Object } [filter ] mongodb selector
19541954 * @return {Query } this
1955- * @see mongodb http://www.mongodb.org/display/DOCS/Aggregation#Aggregation-Count
19561955 * @api public
19571956 */
19581957
1959- Query . prototype . count = function ( criteria ) {
1960- this . op = 'count ' ;
1958+ Query . prototype . countDocuments = function ( filter ) {
1959+ this . op = 'countDocuments ' ;
19611960 this . _validate ( ) ;
19621961
1963- if ( Query . canMerge ( criteria ) ) {
1964- this . merge ( criteria ) ;
1962+ if ( Query . canMerge ( filter ) ) {
1963+ this . merge ( filter ) ;
19651964 }
19661965
19671966 return this ;
19681967} ;
19691968
19701969/**
1971- * Executes a `count ` Query
1970+ * Executes a `countDocuments ` Query
19721971 * @returns the results
19731972 */
1974- Query . prototype . _count = async function _count ( ) {
1975- const conds = this . _conditions ,
1976- options = this . _optionsForExec ( ) ;
1973+ Query . prototype . _countDocuments = async function _countDocuments ( ) {
1974+ const conds = this . _conditions ;
1975+ const options = this . _optionsForExec ( ) ;
19771976
1978- return this . _collection . count ( conds , options ) ;
1977+ return this . _collection . countDocuments ( conds , options ) ;
1978+ } ;
1979+
1980+ /**
1981+ * Executes the query as a estimatedDocumentCount() operation.
1982+ *
1983+ * #### Example:
1984+ *
1985+ * query.estimatedDocumentCount();
1986+ *
1987+ * const count = await query.estimatedDocumentCount();
1988+ * console.log('there are %d kittens', count);
1989+ *
1990+ * @return {Query } this
1991+ * @api public
1992+ */
1993+
1994+ Query . prototype . estimatedDocumentCount = function ( ) {
1995+ this . op = 'estimatedDocumentCount' ;
1996+ this . _validate ( ) ;
1997+
1998+ return this ;
1999+ } ;
2000+
2001+ /**
2002+ * Executes a `count` Query
2003+ * @returns the results
2004+ */
2005+ Query . prototype . _estimatedDocumentCount = async function _estimatedDocumentCount ( ) {
2006+ const conds = this . _conditions ;
2007+ const options = this . _optionsForExec ( ) ;
2008+ return this . _collection . estimatedDocumentCount ( conds , options ) ;
19792009} ;
19802010
19812011/**
@@ -2313,7 +2343,7 @@ Query.prototype._findOneAndUpdate = async function() {
23132343} ;
23142344
23152345/**
2316- * Issues a mongodb [findAndModify](http://www.mongodb.org/display/DOCS/findAndModify+Command) remove command .
2346+ * Issues a mongodb findOneAndDelete .
23172347 *
23182348 * Finds a matching document, removes it, returning the found document (if any).
23192349 *
@@ -2323,28 +2353,25 @@ Query.prototype._findOneAndUpdate = async function() {
23232353 *
23242354 * #### Examples:
23252355 *
2326- * await A.where().findOneAndRemove(conditions, options) // executes
2327- * A.where().findOneAndRemove(conditions, options) // return Query
2328- * await A.where().findOneAndRemove(conditions) // executes
2329- * A.where().findOneAndRemove(conditions) // returns Query
2330- * await A.where().findOneAndRemove() // executes
2331- * A.where().findOneAndRemove() // returns Query
2332- * A.where().findOneAndDelete() // alias of .findOneAndRemove()
2356+ * await A.where().findOneAndDelete(conditions, options) // executes
2357+ * A.where().findOneAndDelete(conditions, options) // return Query
2358+ * await A.where().findOneAndDelete(conditions) // executes
2359+ * A.where().findOneAndDelete(conditions) // returns Query
2360+ * await A.where().findOneAndDelete() // executes
2361+ * A.where().findOneAndDelete() // returns Query
23332362 *
2334- * @param {Object } [conditions ]
2363+ * @param {Object } [filter ]
23352364 * @param {Object } [options]
23362365 * @return {Query } this
2337- * @see mongodb http://www.mongodb.org/display/DOCS/findAndModify+Command
23382366 * @api public
23392367 */
23402368
2341- Query . prototype . findOneAndRemove = Query . prototype . findOneAndDelete = function ( conditions , options ) {
2342- this . op = 'findOneAndRemove ' ;
2369+ Query . prototype . findOneAndDelete = function ( filter , options ) {
2370+ this . op = 'findOneAndDelete ' ;
23432371 this . _validate ( ) ;
23442372
2345- // apply conditions
2346- if ( Query . canMerge ( conditions ) ) {
2347- this . merge ( conditions ) ;
2373+ if ( Query . canMerge ( filter ) ) {
2374+ this . merge ( filter ) ;
23482375 }
23492376
23502377 // apply options
@@ -2357,7 +2384,7 @@ Query.prototype.findOneAndRemove = Query.prototype.findOneAndDelete = function(c
23572384 * Executes a `findOneAndRemove` Query
23582385 * @returns the results
23592386 */
2360- Query . prototype . _findOneAndRemove = async function ( ) {
2387+ Query . prototype . _findOneAndDelete = async function ( ) {
23612388 const options = this . _optionsForExec ( ) ;
23622389 const conds = this . _conditions ;
23632390
0 commit comments