U kunt $size
gebruiken
aggregatie-operator om de lengte van een array te vinden.
company.aggregate([
{ "$lookup": {
"from": "userFocus",
"localField": "_id",
"foreignField": "value",
"as": "focusUsers"
}},
{ "$project": {
"name": 1,
"focusUsers": 1,
"focusCount": { "$size": "$focusUsers" }
}}
])