I have a collection documents looks like:
{
"_id" : ObjectId("560ba1e86db58e34168b456a"),
"object_id" : "1722224",
"user" : {
"id" : null,
"cookie" : "sEnAl9DdPHyTdmxYU3E23g"
},
"createddate" : ISODate("2015-09-30T11:48:40.000+03:00"),
"activity" : [
{
"name" : "Map click",
"selector" : "#toMap",
"event" : "click",
"time" : ISODate("2015-09-30T12:30:59.000+03:00")
},
{
"name" : "Show contacts (main block)",
"selector" : "#jsn-showContacts",
"event" : "click",
"time" : ISODate("2015-09-30T11:48:47.687+03:00")
},
{
"name" : "Show contacts (main block)",
"selector" : "#jsn-showContacts",
"event" : "click",
"time" : ISODate("2015-09-30T15:34:12.000+03:00")
}
]
}
I need to pass to mongodb range of dates and get a day-by-day result that contains: 1. Date 2. Set of selectors clicked that date and count of that clicks:
{
"date" : ISODate("2015-09-29T00:00:00.000+03:00"),
"selectors" : [
{"#toMap" : 100},
{"#jsn-showContacts" : 200}
]
},
{
"date" : ISODate("2015-09-30T00:00:00.000+03:00"),
"selectors" : [
{"#toMap" : 50},
{"#jsn-showContacts" : 80},
{"#toOrder" : 10}
]
}
The result should count click once for every document, for example if i have two #showContacts-Min clicks in one document:
"activity" : [
{
"name" : "Show contacts (main block)",
"selector" : "#jsn-showContacts",
"event" : "click",
"time" : ISODate("2015-09-30T11:48:47.687+03:00")
},
{
"name" : "Show contacts (main block)",
"selector" : "#jsn-showContacts",
"event" : "click",
"time" : ISODate("2015-09-30T15:34:12.000+03:00")
}
]
it have to be couned once.
Is it really possible to do on DB side as one query or should it be implemented on application side with multiple db queries?