Hi,
I'm trying to show some stats based on the info I have in my collection. For this, I've been following this tutorial:
http://docs.runmyprocess.com/Developer_Guide/Web_Interface/Design/Charts/Chart_Dashboard_Collection
but I need to do something that I don't if it's possible on MongoDB.
I want to make two counts of two distict fields( something like
SELECT Count(x), Count(y) FROM T1 GROUP BY date; more or less)
I've been reading aggreation functions on MongoDB doc, but I don't know how ca i make this. For counting, only one field, I've made this:
var pipelines =
[
{
"$group": {
"_id": {
"fecha":"$fecha"
},
"count":{
"$sum":1
}
}
},
{
"$project":{
"DATE":"$_id.fecha",
"TOTAL":"$count"
}
}
];
...and it works perfectly. But I now need to count not only the number of documents for each date, I need to count the number of places, and I had thougth something like this:
var my_pipelines =
[
{
"$group":
{
"_id": {
"fecha":"$fecha",
"ticket_id": "$ticket_id",
},
"count_tickets":{
"$sum":1
},
}
},
{
"$group":
{
"_id": {
"fecha":"$fecha",
"location": "$location"
},
"count_places":{
"$sum":1
}
}
},
{
"$project":
{
"DATE":"$_id.fecha",
"TOTAL_TICKETS":"$count_tickets",
"TOTAL_PLACES":"$count_places"
}
}
];
But It seems that, two groups clauses are not allowed.
How can I count two distinct fields?
I would thank some help, please.
Regards