-
Type: Bug
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.6.1, 2.7.0
-
Component/s: Write Ops
-
Query Optimization
-
ALL
Regression introduced in 2.5.5 by SERVER-11389.
Upsert operations will fail with error "Cannot create base during insert of update" when the query document includes multiple equality predicates on the same field. Query predicates that use $all are affected; query predicates that use $and with multiple predicates that are explicitly given on the same field are also affected.
See the following example:
> db.version() 2.6.1 > db.foo.drop() false > db.foo.update({a:{$all:[0,1]}},{$set:{b:1}},{upsert:true}) WriteResult({ "nMatched" : 0, "nUpserted" : 0, "writeError" : { "code" : 12, "errmsg" : "Cannot create base during insert of update. Caused by :ConflictingUpdateOperators Cannot update 'a' and 'a' at the same time" } })
The following illustrates how to work around the issue in the above example:
> db.foo.update({$and:[{a:{$elemMatch:{$lte:0,$gte:0}}},{a:{$elemMatch:{$lte:1,$gte:1}}}]},{$set:{b:1}},{upsert:true}) WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : ObjectId("53691eda8f8f0d777fb2be69") })
Original report from mongodb-user: <https://groups.google.com/forum/#!topic/mongodb-user/UcKvx4p4hnY>
- is duplicated by
-
SERVER-23632 Take field value from $setOnInsert when it cannot be inferred otherwise
- Closed
- related to
-
SERVER-3946 Update with $addToSet/$push with a query on same field is broken during insert
- Closed