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

$setIsSubset not working on undefined when used in $lookup.pipeline

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      Context

      Given the following code:

       

      db.t.t.insertOne({"title": "test"}) db.t.t.aggregate([{"$lookup": {"as": "__subquery0", "from": "pepe", "let":
      {"parent__field__0": "$field"}
      , "pipeline": [{"$match": {"$expr":
      {"$literal": false}
      }}, {"$match": {"$expr": {"$and": [
      {"$setIsSubset": ["$field", "$$parent__field__0"]}
      ]}}}]}}])
      

       
      raises:

      MongoServerError[Location17311]: PlanExecutor error during aggregation :: caused by :: Failed to optimize pipeline :: caused by :: Failed to optimize expression :: caused by :: Failed to optimize expression :: caused by :: both operands of $setIsSubset must be arrays. Second argument is of type: missing

       
      Note: the lookup subquery has a {$match: {$expr: {$literal: false }}} to get an empty result.
      and If a setIsSubset is used in a empty result but not inside a $lookup:

      db.t.t.aggregate([{"$match": {"$expr":
      {"$literal": false}
      }}, {"$project": {expr:
      {'$setIsSubset': ['$field', '$something']}
      }}])
      

       
      It didn't raise an error, just return an empty result.Note2: it seems to have something to do with the parent_fields, if the subquery does not use parent_field_0, it works:

      db.t.t.aggregate([{"$lookup": {"as": "__subquery0", "from": "pepe", "let":
      {"parent__field__0": "$field"}
      , "pipeline": [{"$match": {"$expr":
      {"$literal": false}
      }}, {"$match": {"$expr": {"$and": [
      {"$setIsSubset": ["$field", "$aa"]}
      ]}}}]}}])
      

       
      Mongo version is:
      Using MongoDB: 7.0.16
      Using Mongosh: 2.3.0
      -----------------
      Additional attempts
      Example using an undefined fieldname (`$aa`)
      (Attached as image.png)
      Example of a failed query using the $$parent_field_0
      (Attached as image (1).png)

        1. image (1).png
          image (1).png
          160 kB
        2. image.png
          image.png
          159 kB

            Assignee:
            ivan.fefer@mongodb.com Ivan Fefer
            Reporter:
            jib.adegunloye@mongodb.com Jib Adegunloye
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: