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

UpdatedExisting always true after update command

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.5
    • Affects Version/s: 2.5.4
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • ALL

      getLastError appears to always return true for updatedExisting when the last operation was an update, regardless of whether a document was updated or not.

      > db.test.remove()
      SingleWriteResult({
      	"writeErrors" : [ ],
      	"writeConcernErrors" : [ ],
      	"nInserted" : 0,
      	"nUpserted" : 0,
      	"nUpdated" : 0,
      	"nModified" : 0,
      	"nRemoved" : 2,
      	"upserted" : [ ]
      })
      > db.test.insert({i: 1})
      SingleWriteResult({
      	"writeErrors" : [ ],
      	"writeConcernErrors" : [ ],
      	"nInserted" : 1,
      	"nUpserted" : 0,
      	"nUpdated" : 0,
      	"nModified" : 0,
      	"nRemoved" : 0,
      	"upserted" : [ ]
      })
      > db.test.update({i: 5}, {$set: {i: 500}})
      SingleWriteResult({
      	"writeErrors" : [ ],
      	"writeConcernErrors" : [ ],
      	"nInserted" : 0,
      	"nUpserted" : 0,
      	"nUpdated" : 0,
      	"nModified" : 0,
      	"nRemoved" : 0,
      	"upserted" : [ ]
      })
      > db.runCommand('getLastError')
      {
      	"updatedExisting" : true,
      	"n" : 0,
      	"connectionId" : 2291,
      	"syncMillis" : 0,
      	"writtenTo" : null,
      	"err" : null,
      	"ok" : 1
      }
      > db.test.find()
      { "_id" : ObjectId("52d07a4cd05c85fb8d3f5e3d"), "i" : 1 }
      > db.test.update({i: 5}, {$set: {i: 1}})
      SingleWriteResult({
      	"writeErrors" : [ ],
      	"writeConcernErrors" : [ ],
      	"nInserted" : 0,
      	"nUpserted" : 0,
      	"nUpdated" : 0,
      	"nModified" : 0,
      	"nRemoved" : 0,
      	"upserted" : [ ]
      })
      > db.runCommand('getLastError')
      {
      	"updatedExisting" : true,
      	"n" : 0,
      	"connectionId" : 2291,
      	"syncMillis" : 0,
      	"writtenTo" : null,
      	"err" : null,
      	"ok" : 1
      }
      > db.test.find()
      { "_id" : ObjectId("52d07a4cd05c85fb8d3f5e3d"), "i" : 1 }
      

            Assignee:
            randolph@mongodb.com Randolph Tan
            Reporter:
            bernie@mongodb.com Bernie Hackett
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: