面试题答案
一键面试db.user_actions.aggregate([
{
$group: {
_id: {
user_id: "$user_id",
action_type: "$action_type",
action_date: { $dateToString: { format: "%Y-%m-%d", date: "$action_time" } }
},
total_value: { $sum: "$value" },
count: { $sum: 1 }
}
},
{
$match: {
count: { $gt: 10 }
}
},
{
$group: {
_id: {
action_type: "$_id.action_type",
action_date: "$_id.action_date"
},
average_value: { $avg: "$total_value" }
}
}
]);