I have only experience with RDBS. There is it possible to aggregate fields by more than one field.
t_example:
country | city | val | useless
---------------------------------------
Ger | Ber | 10 | abc
Ger | Ber | 10 | abc
Ger | MU | 10 | abc
FR | Par | 10 | abc
SELECT country,city,sum(val) FROM t_example GROUP BY country,city;
=>
country | city | val
----------------------------
Ger | Ber | 20
Ger | MU | 10
FR | Par | 10
Is it possible to get the same result by MongoDB if a collection contains the same Values on JSON files? I tried this on NodeJS:
dbs.collection('t_example').aggregate([{ $group: { "_id": "$country","count":{$sum:1}}}]).toArray(function(error,result){
res.json(result);
});
I got a similiar result:
[{"_id":"Ger","count":30},{"_id":"Fr","count":10}]
Is it possible to break down the data by an additional field (city)? I also can´t change the key (_id). Otherwise the result is an empty Array.
id:{country:"$country", city:"$city"}