Database

db={"products":[{_id:"abc",name:"Pizza",attributes:[{salePrice:250,size:"Small"},{salePrice:300,size:"Medium"},{salePrice:350,size:"Large"}]},{_id:"xyz",name:"Burger",attributes:[{salePrice:100,size:"Regular"},{salePrice:150,size:"Large"}]}],"cart":[{cartProducts:[{productId:"xyz",type:"Large",quantity:5},{productId:"abc",type:"Regular",quantity:2}]}]}

Query

db.cart.aggregate([{$lookup:{from:"products",localField:"cartProducts.productId",foreignField:"_id",as:"products"}},{$project:{cartProducts:{$map:{input:"$cartProducts",as:"p",in:{$mergeObjects:["$$p",{$reduce:{input:"$products",initialValue:{},in:{$cond:[{$eq:["$$this._id","$$p.productId"]},{name:"$$this.name",salePrice:{$reduce:{input:"$$this.attributes",initialValue:0,in:{$cond:[{$eq:["$$this.size","$$p.type"]},"$$this.salePrice","$$value"]}}}},"$$value"]}}}]}}}}}])

Result