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

Implement "$inc" update operator #71

Closed
tatu-at-datastax opened this issue Feb 3, 2023 · 2 comments · Fixed by #83
Closed

Implement "$inc" update operator #71

tatu-at-datastax opened this issue Feb 3, 2023 · 2 comments · Fixed by #83
Assignees

Comments

@tatu-at-datastax
Copy link
Contributor

It looks like "$inc" operator has relatively simple limits (see https://www.mongodb.com/docs/manual/reference/operator/update/inc/ for full description):

  • May be used on number-valued fields/elements
  • May be used on missing (non-existing) fields/elements
  • May NOT be used on non-number-valued elements (this includes null)

So it seems like a good candidate for implementation.

@tatu-at-datastax tatu-at-datastax self-assigned this Feb 3, 2023
@tatu-at-datastax tatu-at-datastax changed the title Implement "$inc" update operation Implement "$inc" update operator Feb 3, 2023
@tatu-at-datastax
Copy link
Contributor Author

@vkarpov15 Does Mongoose use $inc extensively? I think implementation should be relatively straight-forward, but for priority/ordering it is good to know which features benefit project most.

@vkarpov15
Copy link
Collaborator

I added some notes here: https://gist.github.com/vkarpov15/d24c95f5590f8c4c3f92388646da01df .

A little more detail: yes, Mongoose does make heavy use of $inc by default. Specifically, Mongoose's default concurrency strategy for save() is a form of optimistic concurrency that kicks in only when there is a potentially conflicting array operation. For example, updating updates.0.quantity when someone else has removed updates.0. So, by default, adding an element to an array using push() and then calling save() triggers a $inc on the version key.

Because this behavior is the default and sufficiently unintrusive, most developers don't end up configuring the concurrency strategy. So most apps will end up using $inc under the hood.

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 a pull request may close this issue.

2 participants