Skip to content
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

fix(query): shallow clone $or, $and if merging onto empty query filter #14580

Merged
merged 6 commits into from May 11, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #14567

Summary

Currently, when you call TestModel.find({ $and }), Mongoose doesn't clone the $and. Then Query.prototype.and() uses push() to add onto the $and array, which modifies the existing $and array.

We already have some logic in place from #12944 that shallow clones $and, $or if they're set, but that only currently kicks in if there's an existing $and / $or. With this PR, we'll do a shallow clone on $and, $or if they exist on the user's provided query filter.

Examples

lib/utils.js Dismissed Show dismissed Hide dismissed
Copy link
Contributor

@sderrow sderrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just a couple thoughts.

lib/query.js Outdated Show resolved Hide resolved
lib/query.js Outdated Show resolved Hide resolved
lib/utils.js Outdated Show resolved Hide resolved
vkarpov15 and others added 4 commits May 9, 2024 11:21
Co-authored-by: Sean Derrow <sean.derrow@gmail.com>
Co-authored-by: Sean Derrow <sean.derrow@gmail.com>
@vkarpov15 vkarpov15 merged commit 3526799 into master May 11, 2024
34 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-14567 branch May 11, 2024 15:33
vkarpov15 added a commit that referenced this pull request May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filter is mutated in place by Query modifiers
2 participants