MongoDB - lookup - multiple collection - Result in one array
You can try lookup with pipeline,
$lookup
with nodes and passsiteId
to pipeline$match
siteId
condition$lookup
withdevices
and passdeviceId
to pipeline$match
deviceId
condition$lookup
withsensors
collection
db.sites.aggregate([ { $lookup: { from: "nodes", let: { siteId: "$_id" }, pipeline: [ { $match: { $expr: { $eq: ["$$siteId", "$siteId"] } } }, { $lookup: { from: "devices", let: { nodeId: "$_id" }, pipeline: [ { $match: { $expr: { $eq: ["$$nodeId", "$nodeId"] } } }, { $lookup: { from: "sensors", localField: "_id", foreignField: "deviceId", as: "sensors" } } ], as: "devices" } } ], as: "nodes" } }])