Returns an aggregation of the last n elements within a group. The elements returned are meaningful only if in a specified sort order.
If the group contains fewer than n elements, $lastN returns all elements in the group.
$lastN(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 last n elements within a group. The elements returned are meaningful only if in a specified sort order. If the group contains fewer than n elements, $lastN returns all elements in the group.