Mongo Playground

Configuration

db={"profile":[{"_id":"1","name":"gk"}],"subs":[{"_id":"1","username":"gk","f1":"f1","f2":"f1","f3":"f1","f4":"f1"},{"_id":"2","username":"gk","f1":"f1","f2":"f3","f3":"f4","f4":"f5"}]}

Query

db.subs.aggregate([{$lookup:{from:"profile",localField:"username",foreignField:"name",as:"PROFILE"}},{$set:{"PROFILE0":{$arrayElemAt:["$PROFILE",0]},}},{$unset:"PROFILE"}])

Result