Database
db={"basic_info":[{_id:"bmasndvhjbcw",name:"lucas",occupation:"scientist",present_working:true,age:55,location:"texas",},{_id:"bmasndvhjbcx",name:"mark",occupation:"scientist",age:45,present_working:true,location:"texas",},{_id:"bmasndvhjbcq",name:"cooper",occupation:"physicist",age:69,location:"texas"}],"test_results":[{basic_id:"bmasndvhjbcw",test_results:"PASS"},{basic_id:"bmasndvhjbcx",test_results:"PASS"},{basic_id:"bmasndvhjbcq",test_results:"FAIL"}]}
Query
db.basic_info.aggregate([{$lookup:{from:"test_results",let:{id:"$_id"},pipeline:[{$match:{test_results:"PASS",$expr:{$eq:["$basic_id","$$id"]}}},{$project:{_id:0,test_results:1}}],as:"test_results"}},{$match:{"test_results.0":{$exists:true}}},{$replaceRoot:{newRoot:{$mergeObjects:["$$ROOT",{$arrayElemAt:["$test_results",0]}]}}}])