汇总查询:
db.events.aggregate([
{$match: { "generated_at": {
"$gte": new Date(2017, 0, 1),
"$lte": new Date(2017, 3, 1)
}, game_id: ObjectId("59de213e9c43f70001c29bef"), event_type: "session"}},
{$project: { generated_at: "$generated_at", user_device_id: "$user_device_id",
avg_user_session_duration: {
$avg: "$session_duration"
}
}},
{$group: { _id: {day: { $dayOfMonth: "$generated_at"}, month: {$month: "$generated_at"}, year: { $year: "$generated_at"} },
avg_session_duration_per_user: {
$avg: "$avg_user_session_duration"
}
}},
{$sort: {"_id.year": 1, "_id.month": 1, "_id.day": 1}}
])
索引:
{
"v" : 2,
"key" : {
"generated_at" : 1,
"game_id" : 1,
"event_type" : 1,
"impression_type" : 1,
"source_name" : 1
},
"name" : "generated_at_1_game_id_1_event_type_1_impression_type_1_source_name_1",
"ns" : "analyticsdb.events"
}
我有如上所述的聚合查询,它适用于小数据集,但我有超过1000万个大小超过2GB的文档。我正在使用mongo atlas M10实例。我从mongo地图册得到这个警报。 shell也一直在等待查询结果,但从不给出任何响应。