Given a dataset:
{_id: 0, type: \'banana\', amount: 5}
{_id: 1, type: \'banana\', amount: 3}
{_id: 2, type: \'apple\', amount: 8}
{_id: 3, type: \'apple\', a
You can use below aggregation with $sort amount descending followed by $first operator to project max amount document.
$replaceRoot to promote the max amount document to top level.
collection.aggregate([
{$sort:{'amount':-1}},
{$group:{ _id: '$type',group:{$first:'$$ROOT'}}},
{$replaceRoot:{newRoot:"$group"}}
])