Database
db={offers:[{_id:ObjectId("64a6c6ed3f24ff001b74cf9d"),name:"offer name"}],modules:[{_id:ObjectId("64a6c6ed3f24ff001b74cfab"),name:"module name",offerId:ObjectId("64a6c6ed3f24ff001b74cf9d")}],items:[{_id:ObjectId("5e984aea5e6df000399e6b97"),name:"module name",moduleId:ObjectId("64a6c6ed3f24ff001b74cfab")}],notes:[{_id:ObjectId("64c78caf0e5791001b15833c"),name:"note name",itemId:ObjectId("5e984aea5e6df000399e6b97")}]}
Query
db.offers.aggregate([{$match:{_id:ObjectId("64a6c6ed3f24ff001b74cf9d")}},{$lookup:{from:"modules",let:{offerId:"$_id"},pipeline:[{$match:{$expr:{$eq:["$offerId","$$offerId"]}}},{$lookup:{from:"items",let:{moduleId:"$_id"},pipeline:[{$match:{$expr:{$eq:["$moduleId","$$moduleId"]}}},{$lookup:{from:"notes",let:{itemId:"$_id"},pipeline:[{$match:{$expr:{$eq:["$itemId","$$itemId"]}}},{$unset:"itemId"}],as:"notes"}},{$unset:"moduleId"}],as:"items"}},{$unset:"offerId"}],as:"modules"}}])