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/defaults.md
+7-10
Original file line number
Diff line number
Diff line change
@@ -23,20 +23,17 @@ execute that function and use the return value as the default.
23
23
24
24
### The `setDefaultsOnInsert` Option
25
25
26
-
By default, mongoose only applies defaults when you create a new document.
27
-
It will **not** set defaults if you use `update()` and
28
-
`findOneAndUpdate()`. However, mongoose 4.x lets you opt-in to this
29
-
behavior using the `setDefaultsOnInsert` option.
26
+
Mongoose also sets defaults on `update()` and `findOneAndUpdate()` when the `upsert` option is set by adding your schema's defaults to a [MongoDB `$setOnInsert` operator](https://docs.mongodb.org/manual/reference/operator/update/setOnInsert/).
27
+
You can disable this behavior by setting the `setDefaultsOnInsert` option to `false`.
0 commit comments