You can do this using the $lookup aggregation, and probably the best way, as currently filling is dying out from mongo
Project.aggregate([ { "$match": { "_id": mongoose.Types.ObjectId(id) } }, { "$lookup": { "from": Pages.collection.name, "let": { "pages": "$pages" }, "pipeline": [ { "$match": { "$expr": { "$in": [ "$_id", "$$pages" ] } } }, { "$lookup": { "from": Component.collection.name, "let": { "components": "$components" }, "pipeline": [ { "$match": { "$expr": { "$in": [ "$_id", "$$components" ] } } }, ], "as": "components" }}, ], "as": "pages" }} ])
Anthony Winzlet Jul 02 '18 at 5:07 2018-07-02 05:07
source share