-
Type:
Improvement
-
Resolution: Won't Fix
-
Priority:
Minor - P4
-
None
-
Affects Version/s: 1.5.2
-
Component/s: Querying
-
None
-
None
-
3
-
None
-
None
-
None
-
None
-
None
-
None
Add a $noop operations so you can effectively do an insert if some criteria doesn't already exist.
db.coll.update({_id:25, name:"John"}, {$noop:1}, true, false)
This question came up in IRC and is the reason for this request: "I want to insert some data into a collection if and only if it doesn't exist already?"
This can be done with a query + insert but would be closer to the RDBMS version (which is wrapped in a transaction normally) using the syntax above (which is atomic).
I could also see this working by using a null second param for update (this is not currently allowed), but the $noop is clearer.