Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-13843

Upsert fails with error when query document includes multiple equality predicates on same field

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 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>

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            rassi J Rassi
            Votes:
            14 Vote for this issue
            Watchers:
            20 Start watching this issue

              Created:
              Updated: