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
feat(document): add $inc()
helper that increments numeric paths
#12115
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor nitpick, otherwise LGTM. 👍
Kind of surprised by the number of scenarios we have to take into account for this to work properly.
On second thought, what do you think about the following syntax? How easy would it be to support it? document.counter.$inc(1);
document.friends[3].age.$inc(1); |
@AbdelrahmanHafez |
Re: number of cases, it is mostly just because I'm trying to be more defensive about shipping new features. In the past, we've often had edge cases in new features like "oh this doesn't work with subdocuments". So this time I'm trying to cover every potential bug I can think of with tests. |
Co-authored-by: Hafez <a.hafez852@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fix #11915
Summary
See #11915. Right now, there's no way to use
$inc
withsave()
.doc.num += 2
becomes a$set
.With this change, you can explicitly increment a given path, and when you
save()
, Mongoose will send a$inc
.Examples