-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Critical - P2
-
None
-
Affects Version/s: 6.12.0
-
Component/s: CRUD
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.
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