[SERVER-14609] Add $setOnMissing update operator Created: 18/Jul/14 Updated: 06/Dec/22 Resolved: 29/Jun/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Write Ops |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Mikhail Osher | Assignee: | Backlog - Query Team (Inactive) |
| Resolution: | Won't Do | Votes: | 4 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Assigned Teams: |
Query
|
||||||||||||
| Participants: | |||||||||||||
| Description |
|
Simple $add operator which similar to $set, but will no overwrite value if exists. |
| Comments |
| Comment by Asya Kamsky [ 29/Jun/19 ] |
|
You can see some examples here. This can be done by setting the field to its new value if its $type is "missing" and leaving it "as is" otherwise. |
| Comment by Mark Bigler [ 08/Oct/15 ] |
|
since +1 for this feature. |
| Comment by Mikhail Osher [ 19/Jul/14 ] |
|
Yes, I need simple $add operator like in Memcache. |
| Comment by Eliot Horowitz (Inactive) [ 19/Jul/14 ] |
|
It is just insert, I think you want something like $setOnMissing (dne exist). |
| Comment by Mikhail Osher [ 19/Jul/14 ] |
|
Oh, I was found this operator, but I thought it only works during insert operation, not update. |
| Comment by Eliot Horowitz (Inactive) [ 18/Jul/14 ] |
|
I'm fairly certain $setOnInsert does what you want: http://docs.mongodb.org/manual/reference/operator/update/setOnInsert/ Let us know if I missed something |