Database
db={"books":[{"_id":1,"guides":[ObjectId("5a934e000102030405000000"),ObjectId("5a934e000102030405000001"),ObjectId("5a934e000102030405000002")]}],"guides":[{"_id":ObjectId("5a934e000102030405000000"),"sections":[ObjectId("5a934e000102030405000000"),ObjectId("5a934e000102030405000001"),ObjectId("5a934e000102030405000002")]},{"_id":ObjectId("5a934e000102030405000001"),"sections":[ObjectId("5a934e000102030405000000")]},{"_id":ObjectId("5a934e000102030405000002"),"sections":[ObjectId("5a934e000102030405000001")]}],"sections":[{"_id":ObjectId("5a934e000102030405000000"),"name":"A"},{"_id":ObjectId("5a934e000102030405000001"),"name":"B"},{"_id":ObjectId("5a934e000102030405000002"),"name":"C"}]}
Query
db.books.aggregate([{$lookup:{from:"guides",localField:"guides",foreignField:"_id",as:"guides_arr"}},{$lookup:{from:"sections",localField:"guides_arr.sections",foreignField:"_id",as:"sections_arr"}},{$addFields:{guides_arr:{$map:{input:"$guides_arr",as:"g",in:{$mergeObjects:["$$g",{sections:{$map:{input:"$$g.sections",as:"s",in:{$first:{$filter:{input:"$sections_arr",cond:{$eq:["$$s","$$this._id"]}}}}}}}]}}}}},{$addFields:{guides:{$map:{input:"$guides",as:"g",in:{$first:{$filter:{input:"$guides_arr",cond:{$eq:["$$g","$$this._id"]}}}}}}}},{$unset:["guides_arr","sections_arr"]}])