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(document): apply setters on resulting value when calling Document.prototype.$inc() #13178

Merged
merged 3 commits into from
Mar 17, 2023

Conversation

vkarpov15
Copy link
Collaborator

Fix #13158

Summary

Document.prototype.$inc() doesn't call setters right now, which is a little strange given that findOneAndUpdate() with $inc does call setters.

The biggest wrinkle here is that we're calling setters on the resulting value, not the value passed in to $inc. So $inc('balance', 4) will call setters with balance = 6 + 4 if balance was originally 6. I think this is slightly better because setters are often used for rounding, and we want to make sure devs that are using $inc() instead of += don't run into unexpected binary floating point precision issues.

Examples

lib/document.js Outdated Show resolved Hide resolved
test/document.test.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@IslandRhythms IslandRhythms left a comment

Choose a reason for hiding this comment

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

I think hasezoey is right, otherwise LGTM

@vkarpov15 vkarpov15 merged commit 8d2ee19 into 6.x Mar 17, 2023
@hasezoey hasezoey deleted the vkarpov15/gh-13158 branch March 17, 2023 15:02
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.

None yet

3 participants