I did end up getting it to work. I was confused by the fact that it
seems that the map needs to emit a similar hash as what you're looking
to return in the reduce. Is that accurate?
I found that not including avg, min, and max in the map function
produced different results of those respective methods in the reduce
function.
This is what I ended up with:
map = %Q{
function() {
emit( this.type, {avg: parseFloat(this.data), total:
parseFloat(this.data), count: 1, min: parseFloat(this.data), max:
parseFloat(this.data) } );
}
}
reduce = %Q{
function(key, values) {
var result = {avg: 0.0, total: 0, count: 0.0, min:
values[0].min, max: values[0].max};
values.forEach(function(value){
result.count += value.count;
result.total += value.total;
if (value.max > result.max) { result.max =
value.max };
if (value.min < result.min) { result.min =
value.min };
});
result.avg = result.total / result.count;
return result;
}
}
On Feb 17, 6:05 pm, Marc <
m...@10gen.com> wrote:
> Good evening.
>
> There are two articles in the MongoDB cookbook, which may help.
> Finding Max And Min Values for a given Keyhttp://
cookbook.mongodb.org/patterns/finding_max_and_min_values_for_a...
> Finding Max And Min Values with Versioned Documentshttp://
cookbook.mongodb.org/patterns/finding_max_and_min/