-
Type: Improvement
-
Resolution: Unresolved
-
Priority: 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?
- related to
-
NODE-4423 Type Regressions in 4.8
- Closed