Chiziqli diagramma ma'lumotlarini ko'rsatish uchun yig'ish so'rovim bor.
U quyidagicha:
[
{
"$match": {
"Category": {
"$in": ["Mobile"]
},
"StartTime": {
"$gte": {"$date": "2014-01-29T00:00:00.000Z"},
"$lt": {"$date": "2014-09-29T00:00:00.000Z"}
}
}
},
{
"$group": {
"_id": {
"Category": "$Category",
"Country":"$Country",
"City":"$City",
"day": {
"day":{"$dayOfMonth": "$StartTime"},
"month":{"$month":"$month"},
"year":{"$year":"$year"}
}
},
"UniqueVisits": {
"$sum": 1
},
"Date": {
"$first": "$StartTime"
}
}
},
{
"$project": {
"_id": "$_id.Category",
"Header": {
"$concat": [{"$substr": [{"$month": "$Date"}, 0,2]},
"/",
{"$substr": [{"$dayOfMonth": "$Date"}, 0, 2]},
"/",
{"$substr": [{"$year": "$Date"}, 0, 4]}]
},
"Name": {
"$concat": [
{
"$ifNull": ["$_id.Country","notset"]
},
"~",
{
"$ifNull": ["$_id.City","notset"]
}
]
},
"UniqueVisits": "$UniqueVisits",
}
}
]
Bu yaxshi ishlaydi. Xuddi shunday, menda $hour, $week, $oy yordamida guruhlash orqali soat, hafta va oy bo'yicha chiziqli diagramma bor.
Endi men 0-12 va 12-24 gacha bo'lgan soat davomiyligi va hatto Ertalab (6-12), Peshindan keyin (12-18), Kechqurun (18-24), Tungi (0-) gacha chiziqli diagrammani AM/PM tomonidan qo'shmoqchiman. 6)
Yuqoridagi muddatlar uchun guruhlashni qanday amalga oshirishim mumkinligi haqida har qanday yordam. Oldindan rahmat.
Masalan :
Ma'lumotlar:
{ "_id" : 1, "Date" : ISODate("2014-10-02T19:44:09Z") }
{ "_id" : 2, "Date" : ISODate("2014-10-02T20:44:09Z") }
{ "_id" : 3, "Date" : ISODate("2014-09-03T20:44:09Z") }
{ "_id" : 4, "Date" : ISODate("2014-09-02T20:44:09Z") }
{ "_id" : 5, "Date" : ISODate("2014-09-03T00:00:00Z") }
{ "_id" : 6, "Date" : ISODate("2014-09-03T07:00:00Z") }
{ "_id" : 7, "Date" : ISODate("2014-09-03T14:00:00Z") }
{ "_id" : 8, "Date" : ISODate("2014-10-02T20:47:09Z") }
Har kuni guruhlash uchun AM/PM uchun erishmoqchi bo'lgan narsam quyidagicha:
{ "_id" : "PM", "Count" : 3, "Date" : ISODate("2014-10-02T19:44:09Z") }
{ "_id" : "AM", "Count" : 1, "Date" : ISODate("2014-09-03T00:00:00Z") }
{ "_id" : "AM", "Count" : 4, "Date" : ISODate("2014-09-03T00:00:00Z") }
Ertalab, tushdan keyin, kechqurun, tun uchun esa quyidagicha:
{ "_id" : "Evening", "Count" : 3, "Date" : ISODate("2014-10-02T19:44:09Z") }
{ "_id" : "Evening", "Count" : 1, "Date" : ISODate("2014-09-02T20:44:09Z") }
{ "_id" : "Night", "Count" : 1, "Date" : ISODate("2014-09-03T00:00:00Z") }
{ "_id" : "Morning", "Count" : 1, "Date" : ISODate("2014-09-03T07:00:00Z") }
{ "_id" : "Afternoon", "Count" : 1, "Date" : ISODate("2014-09-03T14:00:00Z") }
{ "_id" : "Evening", "Count" : 1, "Date" : ISODate("2014-09-03T20:44:09Z") }