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(model): disallow updateMany(update) and fix TypeScript types re: updateMany() #15199

Merged
merged 2 commits into from
Jan 24, 2025

Conversation

vkarpov15
Copy link
Collaborator

Fix #15190

Summary

#15190 points out that Model.updateMany(obj) updates all documents using obj, which is risky, especially given that our TypeScript types as written imply that update parameter is optional, meaning updateMany(obj) treats obj as filter rather than update, but the runtime behavior is different.

This PR specifically blocks Model.updateMany(obj, null), while allowing Model.updateOne(obj) and Query.prototype.updateMany(obj, null).

Examples

@vkarpov15 vkarpov15 added this to the 8.10 milestone Jan 23, 2025
Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

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

LGTM, though i think this will require changes for some users.

@vkarpov15
Copy link
Collaborator Author

That is possible, however hopefully unlikely. The updateMany(doc) code path isn't in our current docs or tests. And this doesn't affect the chaining code path, just top-level updateMany().

@vkarpov15 vkarpov15 changed the base branch from master to 8.10 January 24, 2025 20:13
@vkarpov15 vkarpov15 merged commit fa05375 into 8.10 Jan 24, 2025
2 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-15190 branch January 26, 2025 09:43
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.

Calling 'updateMany' without 'update' param leads to entire collection updated by the 'filter' param's data
2 participants