Missing 'let' variable incorrectly serialized as empty object

XMLWordPrintableJSON

    • Query Optimization
    • Fully Compatible
    • ALL
    • v8.0, v7.3, v7.0, v6.0
    • Hide

      Repro attached to linked BF as sharded_repro.js

      Show
      Repro attached to linked BF as sharded_repro.js
    • 124
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Sharded $lookup that uses expressive (let-pipeline) syntax can incorrectly match missing local fields to empty object foreign fields. For example, given query:

      [
          {
              $lookup: {
                  from: coll_foreign.getName(),
                  as: "res",
                  let: {local_a: "$a"},
                  pipeline: [{$match: {$expr: {$eq: ["$$local_a", "$a"]},}}, {$project: {_id: 1}}]
              }
          }
      ], 

      and documents 

      {_id: 1, b: 1}, {_id: 2, a: {}} 

      within both the local and foreign collection, we would expect to see the following documents in the result set:

      {_id: 1, b: 1, res: [{_id: 1}]}, {_id: 2, a: {}, res: [{_id: 2}]}

      Instead, we can see

      {_id: 1, b: 1, res: [{_id: 2}]}, {_id: 2, a: {}, res: [{_id: 2}]}

      Worth looking into whether this serialization error affects non-$lookup cases like those described in SERVER-57403

              Assignee:
              Hana Pearlman
              Reporter:
              Hana Pearlman
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: