Możesz użyć $size
operator agregacji, aby znaleźć długość tablicy.
company.aggregate([
{ "$lookup": {
"from": "userFocus",
"localField": "_id",
"foreignField": "value",
"as": "focusUsers"
}},
{ "$project": {
"name": 1,
"focusUsers": 1,
"focusCount": { "$size": "$focusUsers" }
}}
])