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

WriteResult._id is undefined in case of upsert

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 4.0.6
    • Fix Version/s: 4.1.11
    • Component/s: Shell
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Sprint:
      Dev Tools 2019-05-06, Dev Tools 2019-04-22

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: