Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-59704

Support for $expr clauses in the query predicate of an upsert

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 5.0.2
    • Component/s: None
    • Labels:
      None
    • Query Optimization

      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.

       

       

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            sylvain.chambon@mongodb.com Sylvain Chambon
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: