I have a schema like the following:
Event : {
eventType : Number,
created : Date,
}
My end goal is to create a line graph for each eventType that shows how many of each event was posted daily.
I've never tried the MongoDB aggregation functions, so I'm a little confused on how to go about doing this. I read through the MongoDB aggregation documentation and my initial thought is to do two grouping and one project passes:
- Group every event into a day
- Group the results of this by
eventType - Project these results so the output is in a nice format to graph.
So my output would look something like this (so I can put it on line graphs:
{
[
{
eventType: 0,
days : [ ISODate(2015-01-01), ISODate(2015-01-02), ISODate(2015-01-03) ],
totals: [ 0, 15, 3 ]
}, {
eventType: 1,
days : [ ISODate(2015-01-01), ISODate(2015-01-02), ISODate(2015-01-03) ],
totals: [ 4, 5, 2 ]
}, {
...
]
}
I'm not sure if conceptually that's correct, and I'm even less sure about the syntax this would require. Any help would be appreciated!