New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(mongoose 6) strict option in find() query doesn't work properly #10602
Comments
The removal of strictQuery option from schema and adding strict to 2nd parameter of Model.find() has been done in #9015 but no details there... The way it is recommended to use {strict: false} option in https://mongoosejs.com/docs/migrating_to_6.html#strictquery-is-removed-and-replaced-by-strict
is quite misleading because the 2nd argument to find() should be the projection (i.e. selecting only specific fields) and not setting options. This is very confusing, considering the current documentation and details found in migrating_to_6.html Until this bug is fixed and the documentation is properly updated, I'll have to revert to Mongoose 5... I've spent too much time trying to debug this and getting nowhere. |
You're right, the 2nd argument to |
@vkarpov15 Thanks for clarifying! Perhaps some explanation for the new |
@lorand-horvath done 👍 |
Node: 12.22.5
Mongoose: 6.0.0
MongoDB Atlas: 4.4.8
Mongoose 6 introduced a breaking change regarding the behavior of find() queries, which now discard by default any fields in the filter object that aren't found in schema. So this is as if {strict: false} is supplied to the query:
However, if we want to get back to the strict behavior of Mongoose 5 (which didn't discard the notInSchema field and simply returned 0 results if the field was not found in schema), we would need to set {strict: true} in Mongoose 6:
But this throws an error instead of returning 0 results (Mongoose 5 simply returned 0 results). Is this error the intended behavior?
The text was updated successfully, but these errors were encountered: