Skip to content

Commit c1c9498

Browse files
committed
chore: release 6.0.0
1 parent 17569c5 commit c1c9498

File tree

3 files changed

+159
-10
lines changed

3 files changed

+159
-10
lines changed

History.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
6.0.0 / 2025-11-18
2+
==================
3+
* BREAKING CHANGE: Make calling updateOne(), updateMany(), and findOneAndX() with one arg set the query filter rather than the update to line up with modern expectations of optional arguments
4+
* BREAKING CHANGE: remove debug dependency, use node debuglog instead
5+
* BREAKING CHANGE: remove count() and findOneAndRemove(): use countDocuments() and findOneAndDelete() instead
6+
* BREAKING CHANGE: require Node >= 20.19.0
7+
* feat: add findOneAndDelete, findOneAndReplace, countDocuments, estimatedDocumentCount
8+
* feat: use mongodb driver 6 in tests
9+
110
5.0.0 / 2023-02-23
211
==================
312
* BREAKING CHANGE: drop callback support #137 [hasezoey](https://github.com/hasezoey)

README.md

Lines changed: 149 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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);
181191
console.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

186206
Declares 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

192212
Options 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)
205225
await query.findOneAndUpdate()
206226
await query.findOneAndUpdate(updateDocument)
207227
await 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);
209258
if (doc) {
210259
// the document may not be found
211260
console.log(doc);
@@ -259,6 +308,65 @@ const result = await mquery().distinct(match, field);
259308
console.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

264372
Executes the query.
@@ -267,6 +375,22 @@ Executes the query.
267375
const 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

272396
Executes the query and returns a stream.
@@ -361,6 +485,22 @@ mquery().where('age').equals(49);
361485
mquery().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

366506
Specifies an `$exists` condition

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mquery",
3-
"version": "5.0.0",
3+
"version": "6.0.0",
44
"description": "Expressive query building for MongoDB",
55
"main": "lib/mquery.js",
66
"scripts": {

0 commit comments

Comments
 (0)