Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate Max value using Map-Reduce in CouchDB?

I know there's the built-in _stats function that gives you sum, count, min, max, and sumsqr. What I'd like to know is how to calculate just the max in a map-reduce way. I can't come up with a reduce function that will work without some more information.

The only thing I can think of is to use sorting on the value and pick off the first value.

My map function looks like this:

function(doc){
  emit(null, doc.value);
}
like image 797
PPC-Coder Avatar asked Apr 11 '12 14:04

PPC-Coder


1 Answers

This may be also solved by the following

function (key, values, rereduce) {
  return Math.max.apply({}, values);
}
like image 50
red_trumpet Avatar answered Sep 25 '22 21:09

red_trumpet