Je moet $first
. gebruiken aggregatie-operator om het eerste document te retourneren na toepassing van de $group
podium.
ScoreBoardModel.aggregate([
{ "$match": { challenge_id: mongoose.Types.ObjectId(req.body.challenge_id) } },
{ "$lookup": {
"from": "appusers",
"let": { "user_id": "$user_id" },
"pipeline": [{ "$match": { "$expr": { "$eq": [ "$_id", "$$user_id" ] } } }],
"as": "user"
}},
{ "$group": {
"_id": "$user_id",
"value": { "$sum": "$value" },
"appusers": { "$first": "$user" },
}}
])