I am looking for a way to generate some summary statistics using Mongo. Suppose I have a collection with many records of the form
{"name" : "Jeroen", "gender" : "m", "age" :27.53 }
Now I want to get the distributions for gender and age. Assume for gender, there are only values "m" and "f". What is the most efficient way of getting the total count of males and females in my collection?
And for age, is there a way that does some 'binning' and gives me a histogram like summary; i.e. the number of records where age is in the intervals: [0, 2), [2, 4), [4, 6) ... etc?