[SERVER-12537] Support $slice/sort in $addToSet Created: 29/Jan/14 Updated: 06/Dec/22 Resolved: 29/Jun/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Write Ops |
| Affects Version/s: | 2.4.0-rc0 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Glenn Maynard | Assignee: | Backlog - Query Team (Inactive) |
| Resolution: | Won't Do | Votes: | 3 |
| Labels: | operations | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Assigned Teams: |
Query
|
||||
| Participants: | |||||
| Description |
|
|
| Comments |
| Comment by Asya Kamsky [ 29/Jun/19 ] |
|
You can see some examples here. What remains to completely support use case in this ticket would be |
| Comment by Ryan Shumate [ 23/May/17 ] |
|
This would be useful in managing time series data in my schema design. We're handling millisecond resolution data that is stored in an array {'ts': ISODate("2017-05-23T10:50:00.0"), 'data': [ {'ms':1520, 'value':5.1351]}. We'd prefer to use $addToSet over $push so that we can ignore duplicate entries for the same timestamp. However, using $addToSet doesn't allow us to sort the data on entry like $push. This requires an application side sort which is time consuming. Performing the sort on insert the same as $push would be very beneficial. |
| Comment by Glenn Maynard [ 29/Jan/14 ] |
|
I've hit it a couple times. A simple example is storing a limited number of recently-seen IDs, for things like detecting accidental double-submission of an action. That's not exactly an MRU, since there's no need to move IDs which were already in the list to the end. (Of course, you can do simple cases with $push and a query, but that's always true for $addToSet and stops working when combined with other changes.) I don't currently need sorting, that was just copied in by the clone. |
| Comment by Glenn Maynard [ 29/Jan/14 ] |
|
(This is a clone of The rationale for closing addToSet should support $slice, to allow adding to a list without allowing duplicates and limiting the total size of the list in the same operation. (Alternatively, to get the same effect, add an "ignoreDuplicates" boolean flag to $push and $pushAll to make it behave like addToSet, so its $slice modifier can be used.) |
| Comment by Scott Hernandez (Inactive) [ 29/Jan/14 ] |
|
I believe this idea has been rejected for sets, but I pushed the idea before that arrays and set should have the same functionality in update. Do you have a use-case where you want to sort/slice with a set? |