Simplify change streams match expressions for op types update/replace

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Major - P3
    • 8.2.0-rc0
    • Affects Version/s: None
    • Component/s: Change streams
    • None
    • Query Execution
    • Fully Compatible
    • QE 2025-05-12, QE 2025-05-26, QE 2025-06-09
    • None
    • 3
    • TBD
    • None
    • None
    • None
    • None
    • None
    • None
    • 0

      The change stream match expression rewrites for update and replace operations are:

      update:  {op: "u", "o._id": {$exists: false}}
      replace: {op: "u", "o._id": {$exists: true}}
      

      When a change stream matches both updates and replaces, this will result in a match expression such as

      {
        $or: [
          ...
          {
            op: "u", 
            "o._id": {
              $exists: false
            }
          },
          {
            op: "u", 
            "o._id": {
              $exists: true
            }
          },
          ...
        ]
      }
      

      This is verbose and inefficient.
      Instead, the two conditions can be fused to a single, simpler condition

      {
        op: "u"
      }
      

      This also allows further optimizations so that the single op type match can be fused with other op type matches into a single IN list match for the op type, e.g.

      {
        op: {
          $in: [
             "d",
             "i",
             "u"
          ]
        }
      }
      

            Assignee:
            Jan Steemann
            Reporter:
            Jan Steemann
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: