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

updateOne with undefined actions results in lost record

    • 2
    • 0
    • None
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Use Case

      Using the nodejs driver, I'm calling

      collection.updateOne({_id: ObjectId("...")}, {$addToSet: undefined, $inc: undefined})

      This seems dumb, but it is because I have code that omits the various terms if there are no corresponding updates.  When calling MongoClient.connect, I am including ignoreUndefined=true.  

      My expectation is that this would either throw an error – because there are no actions to take (they are both undefined) – or there would be no change to the record at all.  In fact, what happens is that all fields in the record other than _id are gone after this update.  Obviously, that's a disaster.

      I have code that avoids these updates that would do nothing.  But in one particular case I failed to detect this situation and certain critical records were essentially lost.

      I note that if I had called replaceOne() that would be different.  But surely updateOne shouldn't work like this.

      User Experience

      • What is the desired/expected outcome for the user once this ticket is implemented?
      • If bug: What is the number of impacted customers? How severe is the impact? Is anyone blocked or broken?

      Dependencies

      • upstream and/or downstream requirements and timelines to bear in mind

      Risks/Unknowns

      • What could go wrong while implementing this change? (e.g., performance, inadvertent behavioral changes in adjacent functionality, existing tech debt, etc)
      • Is there an opportunity for better cross-driver alignment or testing in this area?
      • Is there an opportunity to improve existing documentation on this subject?

      Acceptance Criteria

      Implementation Requirements

      • The check for "atomic" (dollar prefix keys) operators should take into account the ignoreUndefined setting when determining if those keys will be included in the server command.
      • Throw an error from the driver if all atomic operators are undefined.

      Testing Requirements

      • unit test, spec test sync, etc

      Documentation Requirements

      • DOCSP ticket, API docs, etc

      Follow Up Requirements

      • additional tickets to file, required releases, etc
      • if node behavior differs/will differ from other drivers, confirm with dbx devs what standard to aim for and what plan, if any, exists to reconcile the diverging behavior moving forward

       

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            kduffie@navu.co Kingston Duffie
            Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: