Mongoose 7 strictQuery: Query vs Update
0 reputation · 24 Jun 2023, 07:30 UTC
Mongoose 7 and the strictQuery change
Mongoose 7 switched the default of strictQuery from false to true. Queries that contain fields not defined in the schema now throw a StrictModeError instead of silently ignoring those fields. The sanitizeFilter option strips unknown fields from filters, but only for query operations.
Update operations such as updateOne or findOneAndUpdate remain permissive: non‑schema fields are accepted regardless of the strictQuery setting. This asymmetry creates uncertainty for developers who rely on strictness for both reads and writes, especially in TypeScript projects where the QueryFilterType type definitions are tightly coupled to strictQuery.
Given the lack of a clear migration path or RFC, the community is debating whether strictQuery should also apply to update documents. The decision impacts dynamic schema patterns, plugin compatibility, and compile‑time safety.
Unresolved questions
- Should Mongoose extend the
strictQueryflag to enforce strictness on update operations? - If so, what configuration options or migration strategies would preserve backward compatibility for projects using dynamic schemas?