db.coll1.find()
|
{ key: null }
|
db.coll2.find()
|
{ nested: { no_key: 42 } }
|
{ nested: [ ] }
|
{ nested: [ [ ] ] }
|
{ nested: [ {no_key: 42} ] }
|
|
db.coll1.aggregate([{$lookup: {from:"coll2", localField:"key", foreignField:"nested.key", as:"matched"}}, {$project: {_id:0, "matched._id":0}}])
|
produces
|
{ "key" : null, "matched" : [ { "nested" : { "no_key" : 42 } }, { "nested" : [ { "no_key" : 42 } ] } ] }
|
That is, docs where the "nested.key" path in foreign traverses through an empty array aren't matched to null.
|
|
db.coll2.aggregate([{$lookup: {from:"coll1", localField:"nested.key", foreignField:"key", as:"matched"}}, {$project: {_id:0, "matched._id":0}}])
|
produces
|
{ "nested" : { "no_key" : 42 }, "matched" : [ { "key" : null } ] }
|
{ "nested" : [ ], "matched" : [ { "key" : null } ] }
|
{ "nested" : [ [ ] ], "matched" : [ { "key" : null } ] }
|
{ "nested" : [ { "no_key" : 42 } ], "matched" : [ { "key" : null } ] }
|
Expected: the relationship of "matching on specified keys" should be symmetric and not depend on which of the collections is local and which is foreign.
Also see SERVER-63368 that deals with matching empty arrays at the terminal of a path.
NB: the example above uses empty arrays, but the same behavior applies when the arrays contain non-object values.
|