Database

db={users:[{id:1,name:"Aravinth",prices:[{beginDate:"2022-08-24T07:29:01.639Z",endDate:"2022-08-31T07:29:01.639Z",price:45}]},{id:2,name:"Raja",prices:[{beginDate:"2022-07-25T07:29:01.639Z",endDate:"2022-07-30T07:29:01.639Z",price:55}]}],datasets:[{color:"braun, rose gold",firstBillable:"2022-08-24T07:29:01.639Z",assignedTo:1},{color:"beige, silber",firstBillable:"2022-07-25T07:29:01.639Z",assignedTo:2}]}

Query

db.datasets.aggregate([{"$lookup":{"from":"users","as":"details",let:{assigned_to:"$assignedTo",first_billable:{$toDate:"$firstBillable"}},pipeline:[{$match:{$expr:{$eq:["$id","$$assigned_to"]}}},{$unwind:"$prices"},{"$match":{$expr:{"$and":[{"$gte":["$$first_billable",{$toDate:"$prices.beginDate"}]},{"$lte":["$$first_billable",{$toDate:"$prices.endDate"}]}]}}}]}},{"$addFields":{"details":0,"cg":{$first:"$details.prices.price"}}}])

Result