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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 3.0.0-rc11
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
    • Operating System:
      ALL
    • Steps To Reproduce:
      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 })

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: