As a newcomer to robmongo, I've been tasked with writing queries for a collection that includes keys like "userId" and "deviceModel." My goal is to create a query that shows the number of users for each device model.
Here is the query I have so far:
db.device_data.aggregate([{"$group": {"_id": "$data.deviceModel", "count": {"$sum": 1}}}])
However, this query currently only counts the number of keys for each device, not the number of users.
{
"_id": { "$binary": "AN6GmE7Thi+Sd/dpLRjIilgsV/4AAAg=", "$type": "00" },
"auditVersion": "1.0",
"currentTime": NumberLong(1479301118381),
"data": {
"deviceDesign": "bullhead",
"loginType": "GOOGLE",
...
This is an example of what one key looks like in the collection.