Skip to content

Commit c7f110e

Browse files
committed
docs(migrating_to_8): add note about overwrite to migration guide
1 parent d6cd1db commit c7f110e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

docs/migrating_to_8.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ If you're still on Mongoose 6.x or earlier, please read the [Mongoose 6.x to 7.x
2020
* [`null` is valid for non-required string enums](#null-is-valid-for-non-required-string-enums)
2121
* [Apply minimize when `save()` updates an existing document](#apply-minimize-when-save-updates-an-existing-document)
2222
* [Apply base schema paths before discriminator paths](#apply-base-schema-paths-before-discriminator-paths)
23+
* [Removed `overwrite` option for `findOneAndUpdate()`](#removed-overwrite-option-for-findoneandupdate)
2324
* [Changed behavior for `findOneAndUpdate()` with `orFail()` and upsert](#changed-behavior-for-findoneandupdate-with-orfail-and-upsert)
2425
* [`create()` waits until all saves are done before throwing any error](#create-waits-until-all-saves-are-done-before-throwing-any-error)
2526
* [`Model.validate()` returns copy of object](#model-validate-returns-copy-of-object)
@@ -165,6 +166,15 @@ const doc = new D({ name: 'test', otherProp: 'test' });
165166
console.log(doc.toObject({ getters: true }));
166167
```
167168

169+
<h2 id="removed-overwrite-option-for-findoneandupdate"><a href="#removed-overwrite-option-for-findoneandupdate">Removed <code>overwrite</code> option for <code>findOneAndUpdate()</code></a></h2>
170+
171+
Mongoose 7 and earlier supported an `overwrite` option for `findOneAndUpdate()`, `updateOne()`, and `update()`.
172+
Before Mongoose 7, `overwrite` would skip wrapping the `update` parameter in `$set`, which meant that `findOneAndUpdate()` and `update()` would overwrite the matched document.
173+
In Mongoose 7, setting `overwrite` would convert `findOneAndUpdate()` to `findOneAndReplace()` and `updateOne()` to `replaceOne()` to retain backwards compatibility.
174+
175+
In Mongoose 8, the `overwrite` option is no longer supported.
176+
If you want to overwrite the entire document, use `findOneAndReplace()` or `replaceOne()`.
177+
168178
<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>
169179

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

0 commit comments

Comments
 (0)