Skip to content

Commit f6e5a50

Browse files
committed
docs: add note about deleteOne() changes re: #13369
1 parent 81cba56 commit f6e5a50

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/migrating_to_8.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ you should be aware of when migrating from Mongoose 7.x to Mongoose 8.x.
1212
If you're still on Mongoose 6.x or earlier, please read the [Mongoose 6.x to 7.x migration guide](migrating_to_7.html) and upgrade to Mongoose 7.x first before upgrading to Mongoose 8.
1313

1414
* [Removed `rawResult` option for `findOneAndUpdate()`](#removed-rawresult-option-for-findoneandupdate)
15+
* [`Document.prototype.deleteOne()` now returns a query](#document-prototype-deleteone-now-returns-a-query)
1516
* [Changed behavior for `findOneAndUpdate()` with `orFail()` and upsert](#changed-behavior-for-findoneandupdate-with-orfail-and-upsert)
1617
* [MongoDB Node Driver 6.0](#mongodb-node-driver-6)
1718
* [Removed `findOneAndRemove()`](#removed-findoneandremove)
@@ -36,6 +37,23 @@ const res = await Character.findOneAndUpdate(filter, update, {
3637

3738
`includeResultMetadata` in Mongoose 8 behaves identically to `rawResult`.
3839

40+
<h2 id="document-prototype-deleteone-now-returns-a-query"><a href="#document-prototype-deleteone-now-returns-a-query"><code>Document.prototype.deleteOne</code> now returns a query</a></h2>
41+
42+
In Mongoose 7, `doc.deleteOne()` returned a promise that resolved to `doc`.
43+
In Mongoose 8, `doc.deleteOne()` returns a query for easier chaining, as well as consistency with `doc.updateOne()`.
44+
45+
```javascript
46+
const numberOne = await Character.findOne({ name: 'Will Riker' });
47+
48+
// In Mongoose 7, q is a Promise that resolves to `numberOne`
49+
// In Mongoose 8, q is a Query.
50+
const q = numberOne.deleteOne();
51+
52+
// In Mongoose 7, `res === numberOne`
53+
// In Mongoose 8, `res` is a `DeleteResult`.
54+
const res = await q;
55+
```
56+
3957
<h2 id="changed-behavior-for-findoneandupdate-with-orfail-and-upsert"><a href="#changed-behavior-for-findoneandupdate-with-orfail-and-upsert">Changed behavior for <code>findOneAndUpdate()</code> with <code>orFail()</code> and upsert</a></h2>
4058

4159
In Mongoose 7, `findOneAndUpdate(filter, update, { upsert: true }).orFail()` would throw a `DocumentNotFoundError` if a new document was upserted.

0 commit comments

Comments
 (0)