Skip to content

Commit 6fbe9f0

Browse files
authored
Merge pull request #14998 from markstos/UT-8434-doc-strict-query-flipflop
docs(migration-guide-6x): document that strictQuery default will flip-back
2 parents c068e2f + 3e3dc2e commit 6fbe9f0

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

docs/migrating_to_6.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,16 @@ if (existingUser) {
145145
<h2 id="strictquery-is-removed-and-replaced-by-strict"><a href="#strictquery-is-removed-and-replaced-by-strict"><code>strictQuery</code> is now equal to <code>strict</code> by default</a></h2>
146146

147147
~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`:
151158

152159
```javascript
153160
const userSchema = new Schema({ name: String });
@@ -545,7 +552,7 @@ The MongoDB node driver will always attempt to retry any operation for up to `se
545552
So, it will never run out of retries or try to reconnect to MongoDB.
546553

547554

548-
<h2 id="lodash-object-id"><a href="#lodash-object-id">Lodash <code>.isEmpty()</code> returns true for ObjectIds</h2>
555+
<h2 id="lodash-object-id"><a href="#lodash-object-id">Lodash <code>.isEmpty()</code> returns true for ObjectIds</a></h2>
549556

550557
Lodash's `isEmpty()` function returns true for primitives and primitive wrappers.
551558
`ObjectId()` is an object wrapper that is treated as a primitive by Mongoose.

0 commit comments

Comments
 (0)