-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Labels:
Based on server ticket SERVER-22881, the text in $lookup documentation saying that an $unwind is necessary is no longer accurate.
$unwind may still be used for prettier formatting, but the same can be accomplished on the other side of the $lookup with $project and some other expressions.
Using the same sample documents in the document example, see the following pipeline and output.
db.orders.aggregate([ { $lookup: { from: "inventory", localField: "specs", foreignField: "size", as: "inventory_docs" } }, { $match: { "inventory_docs": { $ne: [] } } } ])
{ "_id" : 1, "item" : "MON1003", "price" : 350, "quantity" : 2, "specs" : [ "27 inch", "Retina display", "1920x1080" ], "type" : "Monitor", "inventory_docs" : [ { "_id" : 1, "sku" : "MON1003", "type" : "Monitor", "instock" : 120, "size" : "27 inch", "resolution" : "1920x1080" } ] }
- related to
-
DOCS-10894 $lookup docs should mention the $lookup+$unwind optimization
- Closed