MongoDB nested lookup with 3 levels
The cause of your ‘troubles’ is the second aggregation stage – { $unwind: “$address” }. It removes record for party with _id: 4 (because its address array is empty, as you mention) and produces two records for parties _id: 1 and _id: 5 (because each of them has two addresses). To prevent removing of parties … Read more