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
- related to
-
SERVER-57403 Serialization error in let variables in a sharded cluster
-
- Closed
-