Database
db={"regCodes":[{"siteId":"123A","registration_code":"ABC","used_flag":true,"Allowed_Use":1,"Remaining_Use":0,"BatchId":"SNGL","CodeDuration":180}],"titleInfo":[{"title":"Principles of Microeconomics","product_form_detail":"EPUB","final_binding_description":"Ebook","vitalsource_enabled":false,"reading_line":"with InQuizitive and Smartwork5","volume":"","protected_content":{"ebookSiteIds":["123A"],"studySpaceSiteIds":[],"iqSiteIds":[]}}]}
Query
db.regCodes.aggregate([{$match:{registration_code:"ABC"}},{$lookup:{from:"titleInfo",let:{regcode_siteId:"$siteId"},pipeline:[{$unwind:{path:"$protected_content.ebookSiteIds",preserveNullAndEmptyArrays:true}},{$unwind:{path:"$protected_content.studySpaceSiteIds",preserveNullAndEmptyArrays:true}},{$unwind:{path:"$protected_content.iqSiteIds",preserveNullAndEmptyArrays:true}},{$match:{$expr:{$or:[{$eq:["$protected_content.ebookSiteIds","$$regcode_siteId"]},{$eq:["$protected_content.studySpaceSiteIds","$$regcode_siteId"]},{$eq:["$protected_content.iqSiteIds","$$regcode_siteId"]}]}}}],as:"regcodeData"}}])