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

db.collection.update() upsert behavior change from 2.6 when query includes predicate on _id

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.0.0-rc11
    • Component/s: Querying
    • Labels:
    • ALL
    • Hide

      Given the following query and update objects:

       q={ "_id.hash" : "e6577bc7" }
       u={ "count" : 43.97}
      

      If we run update, no upsert, no matches, no updates as expected:

      > db.coll_name.update(q,u)
      WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
      

      If we make it an upsert it will fail (this is not the case in 2.6)

      > db.coll_name.update(q,u,upsert=true)
      WriteResult({
      	"nMatched" : 0,
      	"nUpserted" : 0,
      	"nModified" : 0,
      	"writeError" : {
      		"code" : 111,
      		"errmsg" : "field at '_id' must be exactly specified, field at sub-path '_id.hash'found"
      	}
      })
      

      If we have a match for the query, it will succeed. Only the upsert behavior has changed.

      q={ "_id.hash" : "e6577bc37" }
      u={ "count" : 49.97}
      > db.coll_name.update(q,u,upsert=true)
      WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
      
      Show
      Given the following query and update objects: q={ "_id.hash" : "e6577bc7" } u={ "count" : 43.97} If we run update, no upsert, no matches, no updates as expected: > db.coll_name.update(q,u) WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 }) If we make it an upsert it will fail (this is not the case in 2.6) > db.coll_name.update(q,u,upsert= true ) WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 111, "errmsg" : "field at '_id' must be exactly specified, field at sub-path '_id.hash' found" } }) If we have a match for the query, it will succeed. Only the upsert behavior has changed. q={ "_id.hash" : "e6577bc37" } u={ "count" : 49.97} > db.coll_name.update(q,u,upsert= true ) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

      In 2.6 a db.collection.update() upsert with a dotted path _id specification would complete successfully, in 3.0 this behavior has changed, though it is inconsistent between updates and upserts.

      While this behavior is intentional (SERVER-14973), it may cause failures in applications that have inconsistent object notations.

            Assignee:
            ramon.fernandez@mongodb.com Ramon Fernandez Marina
            Reporter:
            michael.grundy Michael Grundy
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: