Chaining .find
with $and
condition overwrites prior conditions
#12944
Labels
enhancement
This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone
Prerequisites
Mongoose version
6.7.0
Node.js version
18.x
MongoDB server version
4.x
Typescript version (if applicable)
No response
Description
Chaining multiple
.find
(or other methods that manipulate the conditions) with$and
(or other array-based conditions) results in the latest method silently overwriting any previous conditions.This issue is relevant specifically for the use-case with the package @casl/mongoose that has utility methods to add constraints to queries based on the ability of an user.
E.g.
The query-conditions generated by
accessibleBy
might be silently overwritten if they happen to utilize$and
and theadditionalConditions
do so too.Steps to Reproduce
Expected Behavior
Since other conditions are merged, I would expect array-conditions to also be merged.
The text was updated successfully, but these errors were encountered: