Database
db={"courses":[{_id:1,title:"maths",members:["p1","p2","s1","s2","s3","s4","s5"]}],"members":[{_id:"p1",name:"Dr. Johnson",type:"professor"},{_id:"p2",name:"Dr. Wong",type:"professor"},{_id:"s1",name:"Alice",type:"student"},{_id:"s2",name:"Bob",type:"student"},{_id:"s3",name:"Chuck",type:"student"},{_id:"s4",name:"Dean",type:"student"},{_id:"s5",name:"Eve",type:"student"}]}
Query
db.courses.aggregate([{"$lookup":{"from":"members","localField":"members","foreignField":"_id","pipeline":[{$match:{"type":"student"}}],"as":"membersLookup"}}])