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

Empty field match expression causes change stream optimization rewrite failure

    • Query Optimization
    • Fully Compatible
    • ALL
    • v8.0, v7.3, v7.0, v6.0, v5.0
    • Hide
      db.test.aggregate([{$changeStream:{ fullDocument: 'updateLookup' }}, {"$match":{"":null}}])
      
      Show
      db.test.aggregate([{$changeStream:{ fullDocument: 'updateLookup' }}, { "$match" :{"": null }}])
    • QO 2024-05-13
    • 152

      A change stream pipeline with empty field path match expression causes tripwire failure. For example:

      db.test.aggregate([{$changeStream:{ fullDocument: 'updateLookup' }}, {"$match":{"":null}}])
      

      The rewrite failure:

      Error: command failed: {                                                              
              "ok" : 0,                                                                                         
              "errmsg" : "Failed to optimize pipeline :: caused by :: Unexpected empty path",                   
              "code" : 5687201,                                                                                 
              "codeName" : "Location5687201"
      }
      

      However, It is actually valid to have an empty field match expression. Removing $changeStream stage returns the results matching the expression in the collection:

      db.test.insert({"": 123}) // not to be returned
      db.test.insert({a: 10}) // to be returned
      db.test.aggregate([{"$match":{"":null}}]) // returns {a: 10} 
      

      We need to fix and relax the restriction to allow empty field path matching.

            Assignee:
            chii.huang@mongodb.com Chi-I Huang
            Reporter:
            chii.huang@mongodb.com Chi-I Huang
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: