Returns an aggregation of the top n elements within a group, according to the specified sort order.
If the group contains fewer than n elements, $topN returns all elements in the group.
$topN(collection, expr, options): unknown[]
Parameters
collection: unknown[]
The input array
expr: unknown
The right-hand side expression value of the operator
Returns an aggregation of the top n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $topN returns all elements in the group.