[SERVER-59704] Support for $expr clauses in the query predicate of an upsert Created: 01/Sep/21 Updated: 06/Dec/22 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 5.0.2 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Sylvain Chambon | Assignee: | Backlog - Query Optimization |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Assigned Teams: |
Query Optimization
|
||||||||||||
| Participants: | |||||||||||||
| Description |
|
We have the following use case:
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.
|
| Comments |
| Comment by Asya Kamsky [ 22/Apr/22 ] |
|
Asked about here: https://www.mongodb.com/community/forums/t/how-to-use-mongodb-date-time-in-filter/159191/2
|