-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: 5.0.2
-
Component/s: None
-
None
-
Query Optimization
-
(copied to CRM)
-
None
-
3
-
None
-
None
-
None
-
None
-
None
-
None
We have the following use case:
- document contains a "version" field that, for legacy reasons, is a string containing an int
- we want to ensure that we are not overriding a newer version of the document
- if no document is present, create it
if "version" was an int, it would be simple: updateOne({ id: XXXX, version: { $lt: newVersion }}, {$set: {...}}, { upsert: true })
as "version" is a string, we have to use: updateOne({ id: XXXX, $where: "parseInt(this.version) < newVersion", {$set: {...}}, { upsert: true })
This has pretty dramatic performance implications, though.
In this use case it would be useful to have support for $expr in the query predicate of an upsert as we could use aggregation expressions such as $toInt instead of $where. The semantics would ideally be the same as with $where - ie the $expr would be discarded when upserting rather than evaluated to figure out if there are fields to be set.
- is duplicated by
-
SERVER-65883 allow $expr in update query predicate with upsert
-
- Closed
-