diff --git a/docs/migrating_to_6.md b/docs/migrating_to_6.md index 69945f4eb0..2de092f66b 100644 --- a/docs/migrating_to_6.md +++ b/docs/migrating_to_6.md @@ -144,9 +144,16 @@ if (existingUser) {

strictQuery is now equal to strict by default

~Mongoose no longer supports a `strictQuery` option. You must now use `strict`.~ -As of Mongoose 6.0.10, we brought back the `strictQuery` option. -However, `strictQuery` is tied to `strict` by default. -This means that, by default, Mongoose will filter out query filter properties that are not in the schema. +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. + +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: + +```javascript +mongoose.set('strictQuery', false); +``` +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. + +Here's an example of the effect of `strictQuery`: ```javascript const userSchema = new Schema({ name: String }); @@ -544,7 +551,7 @@ The MongoDB node driver will always attempt to retry any operation for up to `se So, it will never run out of retries or try to reconnect to MongoDB. -

Lodash .isEmpty() returns true for ObjectIds

+

Lodash .isEmpty() returns true for ObjectIds

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