couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Davis" <>
Subject Re: how do I get the total number of rows returned for a given key?
Date Mon, 25 Aug 2008 17:27:36 GMT
Its gonna depend on the exact keys you're going to be paging through.
But for the base case where you only want to page over exact keys, you
would add in a reduce view with a function like:

    return values.length ;

And then when you query the reduce for the row count for a given key,
make sure you use the group=true parameter.

If instead you're doing sub key matches, you'll have to run through
and calculate the row count for each type of query (read as: You have
to make a new reduce view).

Also remember that if your map functions are byte identical, then only
one btree is generated (which is good). Chris Anderson has an
extremely useful script couchview in his couchrest github repo for
managing views on disk and pushing them into a database. You should be
able to find them at [1].



On Mon, Aug 25, 2008 at 12:10 PM, Patrick Aljord <> wrote:
> On Mon, Aug 25, 2008 at 10:58 AM, Paul Davis
> <> wrote:
>>So while it may look like a pain to get the
>> counts for a specific subset of a view, it really is one of the better
>> solutions.
> ok thanks, could you give me any hint on how to write this reduce in a
> generic way for pagination? I'm writing a mapper for couchdb, is there
> a way to this in a general way so that it can be used for any view or
> is it too specific to each query/view?
> Thanks in advance,
> Pat

View raw message