@@ -50,20 +50,30 @@ const docs = await Artist().find(...).where(...);
5050 - [ Helpers] ( #helpers )
5151 - [ find()] ( #find )
5252 - [ findOne()] ( #findone )
53- - [ count()] ( #count )
53+ - [ countDocuments()] ( #countdocuments )
54+ - [ estimatedDocumentCount()] ( #estimateddocumentcount )
5455 - [ findOneAndUpdate()] ( #findoneandupdate )
5556 - [ findOneAndUpdate() options] ( #findoneandupdate-options )
57+ - [ findOneAndReplace()] ( #findoneandreplace )
58+ - [ findOneAndReplace() options] ( #findoneandreplace-options )
5659 - [ findOneAndRemove()] ( #findoneandremove )
5760 - [ findOneAndRemove() options] ( #findoneandremove-options )
5861 - [ distinct()] ( #distinct )
62+ - [ updateMany()] ( #updatemany )
63+ - [ updateOne()] ( #updateone )
64+ - [ replaceOne()] ( #replaceone )
65+ - [ deleteOne()] ( #deleteone )
66+ - [ deleteMany()] ( #deletemany )
5967 - [ exec()] ( #exec )
68+ - [ cursor()] ( #cursor )
6069 - [ stream()] ( #stream )
6170 - [ all()] ( #all )
6271 - [ and()] ( #and )
6372 - [ box()] ( #box )
6473 - [ circle()] ( #circle )
6574 - [ elemMatch()] ( #elemmatch )
6675 - [ equals()] ( #equals )
76+ - [ eq()] ( #eq )
6777 - [ exists()] ( #exists )
6878 - [ geometry()] ( #geometry )
6979 - [ gt()] ( #gt )
@@ -169,18 +179,28 @@ if (doc) {
169179}
170180```
171181
172- ### count ()
182+ ### countDocuments ()
173183
174- Declares this query a _ count _ query. Optionally pass a match clause.
184+ Declares this query a _ countDocuments _ query. Optionally pass a match clause.
175185
176186``` js
177- mquery ().count ()
178- mquery ().count (match)
179- await mquery ().count ()
180- const number = await mquery ().count (match);
187+ mquery ().countDocuments ()
188+ mquery ().countDocuments (match)
189+ await mquery ().countDocuments ()
190+ const number = await mquery ().countDocuments (match);
181191console .log (' we found %d matching documents' , number);
182192```
183193
194+ ### estimatedDocumentCount()
195+
196+ Declares this query an _ estimatedDocumentCount_ query. Gets an estimated count of documents in a collection using collection metadata.
197+
198+ ``` js
199+ mquery ().estimatedDocumentCount ()
200+ const number = await mquery ().estimatedDocumentCount ();
201+ console .log (' estimated documents: %d' , number);
202+ ```
203+
184204### findOneAndUpdate()
185205
186206Declares this query a _ findAndModify_ with update query. Optionally pass a match clause, update document, options.
@@ -191,7 +211,7 @@ When executed, the first matching document (if found) is modified according to t
191211
192212Options are passed to the ` setOptions() ` method.
193213
194- - ` returnDocument ` : string - ` 'after' ` to return the modified document rather than the original. defaults to ` 'before' `
214+ - ` new ` : boolean - true to return the modified document rather than the original. defaults to false
195215- ` upsert ` : boolean - creates the object if it doesn't exist. defaults to false
196216- ` sort ` : if multiple docs are found by the match condition, sets the sort order to choose which doc to update
197217
@@ -205,7 +225,36 @@ query.findOneAndUpdate(match, updateDocument, options)
205225await query .findOneAndUpdate ()
206226await query .findOneAndUpdate (updateDocument)
207227await query .findOneAndUpdate (match, updateDocument)
208- const doc = await await query .findOneAndUpdate (match, updateDocument, options);
228+ const doc = await query .findOneAndUpdate (match, updateDocument, options);
229+ if (doc) {
230+ // the document may not be found
231+ console .log (doc);
232+ }
233+ ```
234+
235+ ### findOneAndReplace()
236+
237+ Declares this query a _ findOneAndReplace_ query. Finds a matching document, replaces it with the provided replacement, and returns the found document (if any).
238+
239+ #### findOneAndReplace() options
240+
241+ Options are passed to the ` setOptions() ` method.
242+
243+ - ` new ` : boolean - true to return the modified document rather than the original. defaults to false
244+ - ` upsert ` : boolean - creates the object if it doesn't exist. defaults to false
245+ - ` sort ` : if multiple docs are found by the match condition, sets the sort order to choose which doc to replace
246+
247+ ``` js
248+ query .findOneAndReplace ()
249+ query .findOneAndReplace (replacement)
250+ query .findOneAndReplace (match, replacement)
251+ query .findOneAndReplace (match, replacement, options)
252+
253+ // the following all execute the command
254+ await query .findOneAndReplace ()
255+ await query .findOneAndReplace (replacement)
256+ await query .findOneAndReplace (match, replacement)
257+ const doc = await query .findOneAndReplace (match, replacement, options);
209258if (doc) {
210259 // the document may not be found
211260 console .log (doc);
@@ -259,6 +308,65 @@ const result = await mquery().distinct(match, field);
259308console .log (result);
260309```
261310
311+ ### updateMany()
312+
313+ Declares this query an _ updateMany_ query. Updates all documents that match ` criteria ` .
314+
315+ When executed, the first argument is the query, and the second argument is the update document.
316+
317+ _ All paths passed that are not $atomic operations will become $set ops._
318+
319+ ``` js
320+ mquery ().updateMany ({ name: / ^ match/ }, { field: ' value' })
321+ await mquery ().updateMany ({ name: / ^ match/ }, { field: ' value' })
322+ await mquery ().where ({ name: / ^ match/ }).updateMany ({ field: ' value' })
323+ ```
324+
325+ ### updateOne()
326+
327+ Declares this query an _ updateOne_ query. Updates only the first document that matches ` criteria ` .
328+
329+ When executed, the first argument is the query, and the second argument is the update document.
330+
331+ _ All paths passed that are not $atomic operations will become $set ops._
332+
333+ ``` js
334+ mquery ().updateOne ({ name: ' match' }, { field: ' value' })
335+ await mquery ().updateOne ({ name: ' match' }, { field: ' value' })
336+ await mquery ().where ({ name: ' match' }).updateOne ({ field: ' value' })
337+ ```
338+
339+ ### replaceOne()
340+
341+ Declares this query a _ replaceOne_ query. Replaces the first document that matches ` criteria ` with the provided replacement document.
342+
343+ Similar to ` updateOne() ` , except ` replaceOne() ` is not allowed to use atomic modifiers (` $set ` , ` $push ` , etc.). Calling ` replaceOne() ` will always replace the existing doc.
344+
345+ ``` js
346+ mquery ().replaceOne ({ _id: 1 }, { name: ' new name' , age: 25 })
347+ await mquery ().replaceOne ({ _id: 1 }, { name: ' new name' , age: 25 })
348+ ```
349+
350+ ### deleteOne()
351+
352+ Declares this query a _ deleteOne_ query. Deletes the first document that matches ` criteria ` .
353+
354+ ``` js
355+ mquery ().deleteOne ({ name: ' match' })
356+ await mquery ().deleteOne ({ name: ' match' })
357+ await mquery ().where ({ name: ' match' }).deleteOne ()
358+ ```
359+
360+ ### deleteMany()
361+
362+ Declares this query a _ deleteMany_ query. Deletes all documents that match ` criteria ` .
363+
364+ ``` js
365+ mquery ().deleteMany ({ name: / ^ match/ })
366+ await mquery ().deleteMany ({ name: / ^ match/ })
367+ await mquery ().where ({ name: / ^ match/ }).deleteMany ()
368+ ```
369+
262370### exec()
263371
264372Executes the query.
@@ -267,6 +375,22 @@ Executes the query.
267375const docs = await mquery ().findOne ().where (' route' ).intersects (polygon).exec ()
268376```
269377
378+ ### cursor()
379+
380+ Returns a cursor for the given ` find ` query.
381+
382+ ``` js
383+ const cursor = mquery ().find ({ name: / ^ match/ }).cursor ();
384+ cursor .on (' data' , function (doc ) {
385+ console .log (doc);
386+ });
387+ cursor .on (' end' , function () {
388+ console .log (' done' );
389+ });
390+ ```
391+
392+ Note: this only works with ` find() ` operations.
393+
270394### stream()
271395
272396Executes the query and returns a stream.
@@ -361,6 +485,22 @@ mquery().where('age').equals(49);
361485mquery ().where ({ ' age' : 49 });
362486```
363487
488+ ### eq()
489+
490+ Alias of ` equals() ` . Specifies the complementary comparison value for the path specified with ` where() ` .
491+
492+ ``` js
493+ mquery ().where (' age' ).eq (49 );
494+
495+ // is the same as
496+
497+ mquery ().where (' age' ).equals (49 );
498+
499+ // is the same as
500+
501+ mquery ().where ({ ' age' : 49 });
502+ ```
503+
364504### exists()
365505
366506Specifies an ` $exists ` condition
0 commit comments