Unwind, group, sort, then look up the names:
Sort and limit before the $lookup — otherwise you join every tag the user has ever touched and throw most of it away.
asked 2 months ago
1
304
For a profile page I want the ten tags a user has posted under most often. Questions store tags as an array of ObjectIds. I can do it with a loop in JS, but that is a lot of round trips — can this be one aggregation?
Unwind, group, sort, then look up the names:
Sort and limit before the $lookup — otherwise you join every tag the user has ever touched and throw most of it away.
1
of 1
12
0
16
0