-
Type: Improvement
-
Resolution: Won't Fix
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Write Ops
-
None
-
Query
Upsert are rejected with an error if the update meets both conditions:
- _id is assigned to from $setOnInsert
- an equality match on _id is specified in query predicate
See the following reproduction:
> db.foo.update({_id: 0}, {$setOnInsert: {_id: 1}, $set: {x: 1}}, {upsert: true}) WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 66, "errmsg" : "After applying the update to the document {_id: 0.0 , ...}, the (immutable) field '_id' was found to have been altered to _id: 1.0" } })
And, note that this does not generate an error for other fields:
> db.foo.update({z: 0}, {$setOnInsert: {z: 1}, $set: {x: 1}}, {upsert: true}) WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : ObjectId("552eca4fb15badb258938496") }) > db.foo.find() { "_id" : ObjectId("552eca4fb15badb258938496"), "z" : 1, "x" : 1 } >
- is related to
-
SERVER-6913 update allows upsert to "modify" _id
- Closed
- related to
-
SERVER-5289 _id field not taken from query during upsert on update
- Closed