incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <>
Subject Re: counting rows in range queries
Date Thu, 30 Jul 2009 00:48:05 GMT
On Wed, Jul 29, 2009 at 8:38 PM, Fabio Forno<> wrote:
> Hi,
> I've read many threads explaining how to count rows in view results,
> however I can't find any working solution for this particular case.
> I've a set of items divided in buckets, and each item has a posting
> date. I want to divide the items per bucket and sort them by their
> date, so I make a view with this key:
> [item.bucket,]
> Now the difficult part. There are many consumers who retrieve the
> items from the buckets and each consumers knows the date of the last
> item it has retrieved, so I do a range query on the view with
> startkey=[item.bucket, last_date], endkey=[item.bucket, stopper]. This
> is fine, but if I want to tell the user how many items it has to
> retrieve before actually downloading them I can't do nothing but
> retrieving all the rows and start counting. Any idea for solving this
> with a proper map reduce, or some clever doc structure?
> The only possible solution I've found so far is storing marker
> documents for each possible consumer (containing just the item id) any
> time I post a new item in a bucket. These can be counted with a
> map/reduce and deleted when the items are retrieved, but I really
> don't like the solution since it requires too many writes.
> bye!
> --
> Fabio Forno, Ph.D.
> Bluendo srl
> jabber id:

Does this not work?


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

// Number of rows[bucket,last_date_seen]&endkey=[bucket,blocker]

// Actual rows[bucket,last_date_seen]&endkey[bucket,blocker]&reduce=false

Or am I missing something?

Paul Davis

View raw message