Returns the value that results from applying an expression to the first document in a group of documents that share the same group by key. Only meaningful when documents are in a defined order.
$firsthas the following syntax:
For more information on expressions, see Expressions.
sales collection with the following documents:
Grouping the documents by the
item field, the following operation uses the
$first accumulator to compute the first sales date for each item:
The operation returns the following results: