Database

db={"courses":[{_id:1,title:"Maths",description:"description 1",timeline:"timeline 1",studentGroups:[{group:"A",students:[1,5]},{group:"B",students:[3]}]},{_id:2,title:"Chemistry",description:"description 2",timeline:"timeline 2",studentGroups:[{group:"C",students:[2]},{group:"B",students:[4]}]}],"students":[{_id:1,name:"Henry",age:15},{_id:2,name:"Kim",age:20},{_id:3,name:"Michel",age:14},{_id:4,name:"Max",age:16},{_id:5,name:"Nathan",age:19}]}

Query

db.courses.aggregate([{"$unwind":"$studentGroups"},{"$lookup":{"from":"students","localField":"studentGroups.students","foreignField":"_id","as":"studentGroups.students"}},{$group:{_id:"$_id",title:{$first:"$title"},studentGroups:{$push:"$studentGroups"},description:{$first:"$description"},timeline:{$first:"$timeline"}}}])

Result