I am trying to GROUP BY and COUNT each key in each Mongo document but the keys may differ from document to document. I know how to group and count by explicitly calling each key like this:
db.test.aggregate([{"$group" : {_id:"$vcenter", count:{$sum:1}}}])
but how do I iterate through each key of each document without having to call out keys. I'm thinking a mapreduce function?
Here's a sample document: "key1" : "vmx", "key2" : "type", "key3" : "cpu-idle",
and I'm looking for how many records per key like: "Key1" : 1564 "Key2" : 1565 "Key3" : 458