Aggregation Pipeline
db.orders.aggregate([
{$match: {status: 'paid'}},
{$group: {_id: '$user', total: {$sum: '$amount'}}},
{$sort: {total: -1}}
])파이프라인 기반 집계·변환. SQL의 GROUP BY·JOIN 역할.
db.orders.aggregate([
{$match: {status: 'paid'}},
{$group: {_id: '$user', total: {$sum: '$amount'}}},
{$sort: {total: -1}}
])