My aggregation stages look like:
[
{ $match: { ...someFilters } },
{ $sort: { createdOn: -1 } },
{
$bucket: {
groupBy: $somePropertyInDoc,
output: {
DO_SOMETHING_TO_PICK_FIRST_DOC_IN_THE_BUCKET
}
}
}
]
I am assuming that buckets are arrays of documents which are transformed based on what is specified in the output property.
Is there any way to pick/output the first document from each bucket?