Querying a non-existing field, returns all documents, instead of returning nothing
molaeiali opened this issue · 1 comments
Describe the bug
Querying a non-existing field, returns all documents, instead of returning nothing.
To Reproduce
Steps to reproduce the behavior:
Say we have a users collection like this:
users { name: String }
Notice that users document only has a name property and not an email property, Now if I try:
db.users.find({ email: 'something'})
It will return an empty array as a result, but If I give the same query to the paginate
function, it will return all documents in the Users Collection. Looks like it's throwing out non-existing properties and the query will become {}
so it returns all documents.
Expected behavior
Behave like default Mongoose or MongoDB behavior and return nothing, or do not empty out the query?
UPDATE: I tested MongoDB's default behavior, not mongooses, sorry for the wrong opening of the issue, read this: #185 (comment)
Looks like the problem is mongoose
's strictQuery
setting being true
by default since v6.0.10
Its default will be back to false
from mongoose 7
, until then, mongoose.set('strictQuery', false) is the solution
https://mongoosejs.com/docs/migrating_to_6.html#strictquery-is-removed-and-replaced-by-strict
Automattic/mongoose@c51a40e