Database
db={products:[{"productPrice":[{"rentalContractId":ObjectId("64018dfc8a7d37f378d6c427"),"price":20},{"rentalContractId":ObjectId("64018dfc8a7d37f378d6c426"),"price":10}]}],rentalcontractdetails:[{"_id":ObjectId("64018dfc8a7d37f378d6c427"),"contractType":"8 - Days Rental","contractDaysInNumber":8,"createdAt":"2023-03-03T06:04:44.531Z","isDeleted":false,"isArchived":false},{"_id":ObjectId("64018dfc8a7d37f378d6c426"),"contractType":"4 - Days Rental","contractDaysInNumber":4,"createdAt":"2023-03-03T06:04:44.531Z","isDeleted":false,"isArchived":false}]}
Query
db.products.aggregate([{$lookup:{from:"rentalcontractdetails",localField:"productPrice.rentalContractId",foreignField:"_id",as:"rentalContract",pipeline:[{$project:{contractType:1}}]}},{$project:{_id:0,productPrice:{$map:{input:"$rentalContract",in:{$mergeObjects:[{rentalContractId:"$$this"},{price:{$arrayElemAt:["$productPrice.price",{$indexOfArray:["$productPrice.rentalContractId","$$this._id"]}]}}]}}}}}])