Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-965

updateOne and updateMany must contain at least one atomic operator

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.2.25
    • Fix Version/s: 3.0.0
    • Component/s: MongoDB 3.2, MongoDB 3.4
    • Labels:
    • Environment:
      Any platform.

      Description

      In docs for both methods:
      https://docs.mongodb.com/manual/reference/method/db.collection.updateOne/
      https://docs.mongodb.com/manual/reference/method/db.collection.updateMany/

      you can see:
      > Using the update() pattern of field: value for the update parameter throws an error.

      This is example how mongo shell handles it:

      > db.test.insertOne({_id: 'test', field1: 1, field2: 2});
      { "acknowledged" : true, "insertedId" : "test" }
      > db.test.updateOne({_id: 'test'}, {});
      2017-03-24T00:18:27.129+0300 E QUERY    [main] Error: the update operation document must contain at least one atomic operator :
      DBCollection.prototype.updateOne@src/mongo/shell/crud_api.js:519:1
      @(shell):1:1
      > db.test.updateOne({_id: 'test'}, {});
      

      Then if you try to do updateOne using node driver it will not throw error:

      var testCollection = db.collection('test');
      testCollection.updateOne({_id: 'test'}, {});
      

      and object will be updated and will be looking like this
      {_id: 'test'}
      other fields will be removed.

      This is dangerous operation and if client code made it by mistake it can lead to big problems with data. So, I think updateOne and updateMany should follow reference and throw error in this case.

        Attachments

          Activity

            People

            Assignee:
            kaitlin.mahar Kaitlin Mahar
            Reporter:
            airs0urce Dmitry Eroshenko
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: