You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/migrating_to_8.md
+18Lines changed: 18 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,7 @@ you should be aware of when migrating from Mongoose 7.x to Mongoose 8.x.
12
12
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.
13
13
14
14
*[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)
15
16
*[Changed behavior for `findOneAndUpdate()` with `orFail()` and upsert](#changed-behavior-for-findoneandupdate-with-orfail-and-upsert)
`includeResultMetadata` in Mongoose 8 behaves identically to `rawResult`.
38
39
40
+
<h2id="document-prototype-deleteone-now-returns-a-query"><ahref="#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()`.
// In Mongoose 7, q is a Promise that resolves to `numberOne`
49
+
// In Mongoose 8, q is a Query.
50
+
constq=numberOne.deleteOne();
51
+
52
+
// In Mongoose 7, `res === numberOne`
53
+
// In Mongoose 8, `res` is a `DeleteResult`.
54
+
constres=await q;
55
+
```
56
+
39
57
<h2id="changed-behavior-for-findoneandupdate-with-orfail-and-upsert"><ahref="#changed-behavior-for-findoneandupdate-with-orfail-and-upsert">Changed behavior for <code>findOneAndUpdate()</code> with <code>orFail()</code> and upsert</a></h2>
40
58
41
59
In Mongoose 7, `findOneAndUpdate(filter, update, { upsert: true }).orFail()` would throw a `DocumentNotFoundError` if a new document was upserted.
0 commit comments