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

WriteResult._id is undefined in case of upsert

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.1.11
    • Affects Version/s: 4.0.6
    • Component/s: Shell
    • Labels:
      None
    • Fully Compatible
    • ALL
    • Dev Tools 2019-05-06, Dev Tools 2019-04-22

      The WriteResult from an upsert displays in the shell like so:

      res = db.c.update(..., ..., {upsert: true})
      printjson(res)
      {
      	"nMatched" : 0,
      	"nUpserted" : 1,
      	"nModified" : 0,
      	"_id" : ObjectId("5ca4b9271da31f1c4f6cc755")
      }
      

      However attempting to access the _id returns undefined:

      printjson(res._id)
      undefined
      

      The returned _id can be accessed as res.getUpsertedId()._id, but the value printed for res and the documentation indicate that it should be available as res._id.

            Assignee:
            gabriel.russell@mongodb.com Gabriel Russell (Inactive)
            Reporter:
            bruce.lucas@mongodb.com Bruce Lucas (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: