I'm using Mongodb to try and figure out the average milage in my motor cars collection using the map reduce method. I know how to figure out the minimum value (as displayed below), however I don't know how this works for average. Can anyone help with this? Thanks.
var map = function(){
emit(this.Classification, this.Milage); };
var reduce = function(key, values){
var minvalue = values[0];
values.forEach(function(value){
if(minvalue>value){
minvalue = value;
}
})
return minvalue};
db.ads.mapReduce(map,reduce, {
query: {Classification: "Motor Cars"},
out: {inline: 1}
});