聚合查询:
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 atlas 得到这个警报。此外,shell 只是继续等待查询结果,但从未给出任何响应。