-
Type: Bug
-
Resolution: Won't Fix
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
ALL
-
QE 2022-02-21, QE 2022-03-21
Local collection L: [{lkey:[]}]
Foreign collection F: [{fkey: null},{fkey:undefined},{no_fkey:true}]
Query: db.L.aggregate({$lookup: {from: "F", localField: "lkey", foreignField: "fkey", as: "matched"}}
The query matches all three foreign records to the local record.
According to the comment in
https://github.com/10gen/mongo/blob/f65c3ec8d02162327c80f11fbb1758096a75cbe8/src/mongo/db/pipeline/document_source_lookup.cpp#L839-L842 the behavior doesn't seem to be intentional.
Proposed semantics for matching empty arrays ("matches X" below means "matches value X from the foreign field").
If the local key is "a": {a: []} -> no matches {a: [[], 1]} -> matches [] and 1 {a: [[[]]]} -> matches [[]] (does not match []) {b: []} -> matches null {b: [[]]} -> matches null If the local key is "a.x": {a: {x: []}} -> no matches {a: {x: 1}} -> matches 1 {a: {x: [1, 2]}} -> matches 1 and 2 {a: [{x: 1}, {x: 2}]}} -> matches 1 and 2 {a: {x: [[]]}} -> matches [] {a: {y: 42}} -> matches null {a: {y: []}} -> matches null {a: [{y:[]}]} -> matches null {a: [{y:42}, {x:[]}]} -> matches null {a: [{y:42}, {x:[[]]}]} -> matches null and [] If the local key is "a.x.w": {a: [{x: {w: []}}]} -> no matches {a: [{x:[]}, {x: {w: []}}]} -> matches null {a: [{x:[]}, {x: {w: 1}}]} -> matches null and 1 {a: [{x:[]}, {x: {w: [[]]}}]} -> matches null and []
- is related to
-
SERVER-64006 $lookup matches on paths through arrays differently for local/foreign collections
- Closed
-
SERVER-64060 $lookup doesn't match an array with object that misses the local key to null
- Closed
-
SERVER-63690 Implement path handling of localField when lowering $lookup to SBE
- Closed
-
SERVER-64497 Implement proper semantics for matching missing of some terminals on the path
- Closed
- related to
-
SERVER-64538 Complete TODO listed in SERVER-63368
- Closed