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

GLE upserted _id field should always be filled in

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.3
    • Affects Version/s: None
    • Component/s: Write Ops
    • None

      the id isn't included in at least two cases where it probably should for consistency

      if the _id wasn't generated server-side:
      > db.foo.update({_id:'asdf'}, {$set: {a:'123'}}, true)
      > db.getLastErrorObj()

      { "err" : null, "updatedExisting" : false, "n" : 1, "ok" : true }

      > db.foo.update(

      {a:'asdf'}

      , {_id: 'qwer'}, true)
      > db.getLastErrorObj()

      { "err" : null, "updatedExisting" : false, "n" : 1, "ok" : true }

      if the object already existed:

      > db.foo.update({_id:{$gt: ObjectId("4c2e342e38535540224f7945")}}, {$set: {a:'123'}}, true)
      > db.getLastErrorObj()

      { "err" : null, "updatedExisting" : false, "upserted" : ObjectId("4c2e346538535540224f7946"), "n" : 1, "ok" : true }

      > db.foo.update({_id:{$gt: ObjectId("4c2e342e38535540224f7945")}}, {$set: {a:'123'}}, true)
      > db.getLastErrorObj()

      { "err" : null, "updatedExisting" : true, "n" : 1, "ok" : true }

            Assignee:
            scotthernandez Scott Hernandez (Inactive)
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            3 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: