Skip to content

Commit

Permalink
Merge pull request #14998 from markstos/UT-8434-doc-strict-query-flip…
Browse files Browse the repository at this point in the history
…flop

docs(migration-guide-6x): document that strictQuery default will flip-back
  • Loading branch information
vkarpov15 authored Nov 4, 2024
2 parents c068e2f + 3e3dc2e commit 6fbe9f0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions docs/migrating_to_6.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,16 @@ if (existingUser) {
<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>

~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 });
Expand Down Expand Up @@ -545,7 +552,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.


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

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

0 comments on commit 6fbe9f0

Please sign in to comment.