Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-607

insert / upsert operations should not modify the object to add an _id

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 0.10.0
    • Affects Version/s: None
    • Component/s: Shell API
    • None
    • 3
    • Iteration Xylocarpus Granatum, Iteration Yucca
    • Not Needed

      The legacy shell does not modify the object being inserted.

      Use `forceServerObjectId` to prevent the driver to modify the original object with the _id field.

      To reproduce:

      const item = { 'item': 'qaz', 'price': 10, 'quantity': 2, 'date': new Date('2014-03-01T08:00:00Z') };
      db.sales.insertOne(item);
      console.log(JSON.stringify(item));
      {“item”:“qaz”,“price”:10,“quantity”:2,“date”:“2014-03-01T08:00:00.000Z”,“_id”:“602fe50ec9a59cce9557dc87"}
      

      Expected behavior: item would not have an _id field.

            Assignee:
            alena.khineika@mongodb.com Alena Khineika
            Reporter:
            maurizio.casimirri@mongodb.com Maurizio Casimirri
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: