Database
db={"data":[{_id:ObjectId("639e701ce70098a1516f3397"),uuid:"123abc",content:"hello"},{_id:ObjectId("639e701ce70098a1516f339a"),uuid:"123abc",content:"hi"}],"history":[{_id:ObjectId("6397a5767acbb3f283da2791"),uuid:"123abc",data:[{path:"/hello.json",objectId:"639e701ce70098a1516f3397"},{path:"/hi.json",objectId:"639e701ce70098a1516f339a"}]}]}
Query
db.data.aggregate([{"$lookup":{"from":"history","localField":"uuid","foreignField":"uuid","as":"history"}},{"$set":{"history":{"$first":"$history"}}},{$set:{path_element:{"$filter":{"input":"$history.data","cond":{$eq:[{$toString:"$_id"},"$$this.objectId"]}}}}},{$project:{_id:1,uuid:1,content:1,path:{"$getField":{"field":"path","input":{$first:"$path_element"}}}}}])