[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:
Related
is related to SERVER-21094 $merge operator for updating nested s... Closed
is related to SERVER-22102 New update operator for compare-and-s... Closed
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 ]

SERVER-40381 implemented support for aggregation expressions to specify update for 4.2. 

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 SERVER-1088 is already closed:

+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.
Thanks for clarifying.

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

Generated at Thu Feb 08 03:35:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.