1

Either I'm missing something or is this a possible Node.js driver issue?

const users = await User.find({ 'test.test': { $gt: 0 } }).lean();

None of my User documents contain the test object, therefore none should meet this filter's criteria. However, instead of returning no documents, it's returning all of my user documents. According to the documentation, it should only ever return all of the documents in a collection if no/empty filters are passed?

Edit: I said ignoring filter as it only seems to occur when applying nested filters on undefined properties. For instance, if I add more filter conditions that a few documents meet they'll apply *correctly. Example: User.find({ username: { $exists: true }, 'test.test': { $gt: 0 } }) returns only the user documents where username exists, however they still don't have the test object.

1 Answer 1

1

The issue was resolved by setting the Mongoose Schema strictQuery option to false.

https://mongoosejs.com/docs/guide.html#strictQuery

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.