[SERVER-32714] addToSet with specific fields Created: 16/Jan/18 Updated: 15/Feb/18 Resolved: 15/Feb/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Linar Savion | Assignee: | Asya Kamsky |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Participants: | |||||||||
| Description |
|
Currently when updating an array with subdocuments according to a specific key, i.e. given array
Adding an optional argument to addToSet to consider only specific fields would allow updating multiple subdocuments in a single call by only specifying the unique field. This would both improve performance and reduce oplog size, and it seems like a simple addition. |
| Comments |
| Comment by Asya Kamsky [ 15/Feb/18 ] | |||||||||||||
|
I think this ticket is a duplicate of | |||||||||||||
| Comment by Linar Savion [ 18/Jan/18 ] | |||||||||||||
|
No this does not seem like SERVER-6566 would help this issue... If we want to insert a new set of entries into the array :
Then the $addToSet command will only add elements if they don't exist, so the object after the update (with $addToSet considering only the 'ts' field) will look like:
Note that matching entries are not updated, although it could be an optional argument to override existing values... | |||||||||||||
| Comment by Asya Kamsky [ 18/Jan/18 ] | |||||||||||||
|
If the before document is
What does the after update document look like? I'm not clear on what is being added. New element to "values"? Is this something that | |||||||||||||
| Comment by Linar Savion [ 18/Jan/18 ] | |||||||||||||
|
Hi Asya, for example, say we have a time-series collection where each document similar to this:
Then $addToSet would allow us to easily add new timestamps into the "bucket" (while enforcing no-duplicates), is think this is a pretty common use case for time-series usage of mongodb. Currently the only way to achieve this, is using a bulk of update statements, each inserting a single timestamp if it doesn't exist (see oplog issue mentioned above). the performance benefit of using this would be substantial (both raw insert performance and writing to the journal). | |||||||||||||
| Comment by Asya Kamsky [ 17/Jan/18 ] | |||||||||||||
|
What is the update that you want to perform on the sample array? And how does $addToSet figure into it? | |||||||||||||
| Comment by Mark Agarunov [ 16/Jan/18 ] | |||||||||||||
|
Hello linar-jether, Thank you for the detailed example. I've set the fixVersion to "Needs Triage" for this new feature to be scheduled against our currently planned work. Updates will be posted on this ticket as they happen. Thanks, |