Skip to content

Commit 3e3dc2e

Browse files
committedOct 30, 2024
docs: clarify strictQuery default will flip-flop in "Migrating to 6.x"
Save upgrading users the headache of `strictQuery:true` problems by highlighting that the default is going to change back in Mongoose 7, so they may wish to skip this default behavior change.
1 parent d98b2e7 commit 3e3dc2e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed
 

‎docs/migrating_to_6.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,16 @@ if (existingUser) {
144144
<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>
145145

146146
~Mongoose no longer supports a `strictQuery` option. You must now use `strict`.~
147-
As of Mongoose 6.0.10, we brought back the `strictQuery` option.
148-
However, `strictQuery` is tied to `strict` by default.
149-
This means that, by default, Mongoose will filter out query filter properties that are not in the schema.
147+
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.
148+
149+
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:
150+
151+
```javascript
152+
mongoose.set('strictQuery', false);
153+
```
154+
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.
155+
156+
Here's an example of the effect of `strictQuery`:
150157

151158
```javascript
152159
const userSchema = new Schema({ name: String });

0 commit comments

Comments
 (0)