couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Anderson" <jch...@apache.org>
Subject Re: dual purpose filter/count views
Date Sun, 09 Nov 2008 22:01:48 GMT
On Sun, Nov 9, 2008 at 1:36 PM, Sho Fukamachi <sho.fukamachi@gmail.com> wrote:


> map: function(doc) {
>  if (doc.type == 'my_doc') emit(doc.field, [doc, 1]);
>    }
> reduce: function(keys, values) { return sum(values[1]) }

Anthony's second email has a working idea, but this is how I like to
do it. Will work for any map function, so you can drop the funny array
value from your map.

Reduce:

function(keys, values, rereduce) {
  if (rereduce) {
    return sum(values);
  } else {
    return values.length;
  }
}





-- 
Chris Anderson
http://jchris.mfdz.com

Mime
View raw message