-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
-
Fully Compatible
-
ALL
-
v3.4
-
Query 2017-05-29
db.a.find() { "_id" : ObjectId("58ebbf82016ce019673b111c"), "a" : [ { "_id" : 1 }, { "_id" : 2 } ] } { "_id" : ObjectId("58ebbf8d016ce019673b111d"), "a" : [ { "_id" : 5 }, { "_id" : 12 } ] } > db.b.find() { "_id" : 1 } { "_id" : 2 } { "_id" : 3 } { "_id" : 5 } { "_id" : 12 }
I would expect $lookup using "a._id" as localField to work since SERVER-22881 was fixed, however:
db.a.aggregate({$lookup:{from:"b", localField:"a._id", foreignField:"_id", as:"details"}}) { "_id" : ObjectId("58ebbf82016ce019673b111c"), "a" : [ { "_id" : 1 }, { "_id" : 2 } ], "details" : [ ] } { "_id" : ObjectId("58ebbf8d016ce019673b111d"), "a" : [ { "_id" : 5 }, { "_id" : 12 } ], "details" : [ ] }
"details" is properly populated only if I unwind "a" and use "a._id" or if I create another field first in $addFields or $project from "$a._id" (which makes it a simple array) then it works as localField:
db.a.aggregate({$addFields:{a:"$a._id"}},{$lookup:{from:"b", localField:"a", foreignField:"_id", as:"details"}}) { "_id" : ObjectId("58ebbf82016ce019673b111c"), "a" : [ 1, 2 ], "details" : [ { "_id" : 1 }, { "_id" : 2 } ] } { "_id" : ObjectId("58ebbf8d016ce019673b111d"), "a" : [ 5, 12 ], "details" : [ { "_id" : 5 }, { "_id" : 12 } ] }
- is duplicated by
-
SERVER-28896 $lookup should work right with array dot notation in localField
- Closed
- is related to
-
SERVER-42306 $lookup with an array of sub objects should allow for an option to allow each sub object to find join partners
- Backlog