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

findAndModify returns an empty document with "new" : true flag if the _id value in the query document does not match the _id value in the update document.

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.8.4, 2.0.1
    • Component/s: Write Ops
    • ALL

      This is related to https://jira.mongodb.org/browse/SERVER-4157

      If the _id value in the query document does not match the _id value in the update document, an empty document will be returned.

      To reproduce: (in 1.8.4 or 2.0.1)

      > db.test.drop()
      true
      > db.test.findAndModify({ "query" :

      { "_id" : 0}

      , "update" :

      { "_id" : 1, "name" : "Object 1"}

      , "upsert" : true, "new" : true } );
      { } // an empty document is returned
      > db.test.find()

      { "_id" : 1, "name" : "Object 1" }

      > db.test.findAndModify({ "query" :

      { "_id" : 2, name:"blah"}

      , "update" :

      { "_id" : 2, "name" : "Object 2"}

      , "upsert" : true, "new" : true } );

      { "_id" : 2, "name" : "Object 2" }

      // the expected document is returned
      >

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            barrie Barrie Segal
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: