I have a collection of documents like:
{
"browser" : "firefox",
"version" : "4.0.1"
}
{
"browser" : "firefox",
"version" : "3.6.2"
}
{
"browser" : "ie",
"version" : "8.0"
}
How to count the average of all browsers so the results would be:
global firefox: 66%
global ie: 33%
precise firefox:
4.0.1: 50%
3.6.3: 50%
The tricky part is that I don’t want to provide all Firefox verions available in an array. MongoDB query should find all distinct versions in a collection and count average for all of them.
Thanks in advance!
Here is a solution that produces your statistics with pure numbers (e.g. 0.5 instead of 50%):