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): avoid saving applied defaults if path is deselected #12506

Merged
merged 3 commits into from Oct 3, 2022

Conversation

vkarpov15
Copy link
Collaborator

Fix #12414

Summary

If you load a document with an array deselected const doc = await Model.findOne().select({ arr: 0 }) and then save with no changes, Mongoose will save an empty array. This looks like it applies to all deselected defaults.

This PR makes it so that Mongoose skips deselected defaults when calculating what changed in the document.

Examples

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 tests would be good to have

Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

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

LGTM, would be nice to have tests proving that this works. 👍

@vkarpov15 vkarpov15 merged commit 6e736ee into master Oct 3, 2022
@hasezoey hasezoey deleted the vkarpov15/gh-12414 branch October 3, 2022 16:37
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.

Saving a document that was fetched with .select() causes not selected array to be saved empty
3 participants