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

Investigate improving $set and $setOnInsert type information or documentation

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: TypeScript

      Related: NODE-4423

      $set and $setOnInsert have different semantics from insertOne/insertMany which use OptionalUnlessRequiredId to calculate an insert type that always allows a user to pass in an _id if a particular insert needs a client side calculated _id property. Meanwhile, $set and $setOnInsert ensure any partial amount of your schema that still matches keys to values is permitted. This can be unexpected when you attempt to pass a _id to an update filter that has does not define the property.

      Open Qs:

      • Best approach for clarifying the inconsistency?
      • $setOnInsert can take an _id only in the case where the document already exists.
      • If the value for _id passed to the query does not match the the value passed to $set/$setOnInsert it will raise a write error, can TS help catch this? And if so can documentation explain this accessibly?

            Assignee:
            Unassigned Unassigned
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: