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_6.md
+11-4Lines changed: 11 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -145,9 +145,16 @@ if (existingUser) {
145
145
<h2id="strictquery-is-removed-and-replaced-by-strict"><ahref="#strictquery-is-removed-and-replaced-by-strict"><code>strictQuery</code> is now equal to <code>strict</code> by default</a></h2>
146
146
147
147
~Mongoose no longer supports a `strictQuery` option. You must now use `strict`.~
148
-
As of Mongoose 6.0.10, we brought back the `strictQuery` option.
149
-
However, `strictQuery` is tied to `strict` by default.
150
-
This means that, by default, Mongoose will filter out query filter properties that are not in the schema.
148
+
As of Mongoose 6.0.10, we brought back the `strictQuery` option. In Mongoose 6, `strictQuery` is set to `strict` by default. This means that, by default, Mongoose will filter out query filter properties that are not in the schema.
149
+
150
+
However, this behavior was a source of confusion in some cases, so in Mongoose 7, this default changes back to `false`. So if you want to retain the default behavior of Mongoose 5 as well as Mongoose 7 and later, you can also disable `strictQuery` globally to override:
151
+
152
+
```javascript
153
+
mongoose.set('strictQuery', false);
154
+
```
155
+
In a test suite, it may be useful to set `strictQuery` to `throw`, which will throw exceptions any time a query references schema that doesn't exist, which could help identify a bug in your tests or code.
156
+
157
+
Here's an example of the effect of `strictQuery`:
151
158
152
159
```javascript
153
160
constuserSchema=newSchema({ name:String });
@@ -545,7 +552,7 @@ The MongoDB node driver will always attempt to retry any operation for up to `se
545
552
So, it will never run out of retries or try to reconnect to MongoDB.
546
553
547
554
548
-
<h2id="lodash-object-id"><ahref="#lodash-object-id">Lodash <code>.isEmpty()</code> returns true for ObjectIds</h2>
555
+
<h2id="lodash-object-id"><ahref="#lodash-object-id">Lodash <code>.isEmpty()</code> returns true for ObjectIds</a></h2>
549
556
550
557
Lodash's `isEmpty()` function returns true for primitives and primitive wrappers.
551
558
`ObjectId()` is an object wrapper that is treated as a primitive by Mongoose.
0 commit comments