面试题答案
一键面试db.orders.aggregate([
{
$group: {
_id: "$customer_id",
totalOrderAmount: { $sum: "$total_amount" }
}
},
{
$match: {
totalOrderAmount: { $gt: 1000 }
}
},
{
$sort: {
totalOrderAmount: -1
}
},
{
$project: {
customer_id: "$_id",
totalOrderAmount: 1,
_id: 0
}
}
]);