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

    XMLWordPrintable

Details

    • Bug
    • Status: Backlog
    • Major - P3
    • Resolution: Unresolved
    • 2.6.1, 2.7.0
    • None
    • Write Ops
    • ALL

    Description

      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>

      Attachments

        Issue Links

          Activity

            People

              backlog-query-optimization Backlog - Query Optimization
              rassi J Rassi
              Votes:
              13 Vote for this issue
              Watchers:
              19 Start watching this issue

              Dates

                Created:
                Updated: