incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Candler <>
Subject Re: Finding how many items correspond to a key in a view
Date Fri, 05 Jun 2009 20:00:08 GMT
On Wed, Jun 03, 2009 at 10:54:19PM -0700, Nadav Samet wrote:
> Given a key I'd like to find how many items in a permanent view correspond
> to that key (without retrieving the items themselves, because there can be
> too many).
> I currently achieve it by having another mapreduce just to compute this
> count, but it sounds like there must be a better way.

Sounds like the right way to me. If you have an existing view which does


and as long as this view doesn't already have a reduce function, you can add
a counter reduce function(*) to it. Then you just have to remember to query
it with reduce=false when you *don't* want the counts. (I'd prefer it if you
had to say reduce=true to get the reduction, but that's probably just me :-)



(*) e.g. this one:

function(ks, vs, co) {
  if (co) {
    return sum(vs);
  } else {
    return vs.length;

View raw message