Database

[{"projectName":"Troubleshooting PostgreSQL issues","team":[{"memberId":"cyclops","name":"Cyclops","role":"Postgres Expert"},{"memberId":"wolverine","name":"Wolverine","role":"Consultant"},{"memberId":"storm","name":"Storm","role":"DBA"},{"memberId":"beast","name":"Beast","role":"Developer"},{"memberId":"tony","name":"Tony","role":"Architect"}],"status":"active"},{"projectName":"Build new apps with MongoDB","team":[{"memberId":"tony","name":"Tony","role":"Developer"}],"status":"planned"},/** Member info documents:*/{"memberId":"cyclops","name":"Cyclops","department":"Databases","email":"cyclops@xmen.com","bio":"Postgres expert and leader of the team.","location":"New York"},{"memberId":"wolverine","name":"Wolverine","department":"Consulting","email":"wolverine@xmen.com","bio":"Consultant with years of IT field experience.","location":"Canada"},{"memberId":"storm","name":"Storm","department":"Operations","email":"storm@xmen.com","bio":"DBA and cloud infrastructure specialist.","location":"Africa"},{"memberId":"beast","name":"Beast","department":"Development","email":"beast@xmen.com","bio":"Full-stack developer and automation expert.","location":"Massachusetts"},{"memberId":"tony","name":"Tony","department":"Architecture","email":"tony@xmen.com","bio":"System architect and MongoDB developer.","location":"California"}]

Query

db.collection.aggregate([{$match:{projectName:{$exists:true}}},{$lookup:{from:"members",localField:"team.memberId",foreignField:"memberId",as:"memberInfo"}}])

Result