Details
-
Bug
-
Resolution: Fixed
-
Major - P3
-
None
-
None
-
None
-
Query Execution
-
Fully Compatible
-
ALL
-
v7.0, v6.3, v6.0, v5.0, v4.4
-
QO 2023-05-15
-
105
Description
Repro:
b.l.drop();
|
db.f.drop();
|
assert.commandWorked(db.l.insert([{a: [1]}, {a: {"00": 1}}])); |
assert.commandWorked(db.f.insert({b: 1})); |
|
|
const pipeline1 = [ |
{$lookup: {from: "f", localField: "a.00", foreignField: "b", as: "docs"}} |
];
|
const pipeline2 = [ |
{$_internalInhibitOptimization: {}},
|
{$lookup: {from: "f", localField: "a.00", foreignField: "b", as: "docs"}} |
];
|
|
|
// Uses SBE.
|
jsTestLog(db.l.aggregate(pipeline1).toArray()); // Only {a: {"00": 1}} matches {b: 1} |
// Uses document source $lookup.
|
jsTestLog(db.l.aggregate(pipeline2).toArray()); // Both local documents match {b: 1} |
This is likely because SBE treats localField as a regular $match ($match treats "00"-type fields as field names, not indexes).
Classic $lookup treats "00"-type fields as both an index and a field name. I believe this is unintentional, and likely should be fixed.