couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Stuart (SuperCoders)" <>
Subject Re: Need to get total rows of startkey/endkey range for paging
Date Sat, 02 Apr 2011 20:26:31 GMT
Hi Robert, three points:

1: Your point is a good one Robert - how would the grid cope with the  
number of rows changing between page reads?  I'm using the new extjs4  
so I have asked this on their forum.

2: On the subject of "sending the count of the rows in the current  
startkey/endkey range along with the data",would it be possible to use  
a list to combine the count with the data, in effect putting two views  
together into one, the count view at the top, the data view underneath?

3: Am I correct in understanding that the linked list style pagination  
that you describe works, but only for serial page after page access?   
Random access to any given view page is not possible with this  


On 02/04/2011, at 9:17 PM, Robert Newson wrote:

How will your grid cope with the number of rows changing between your
first query to get the count and subsequently fetching the pages?

I don't think you can know the number of pages of results up front
like this. CouchDB pagination usually follows a different algorithm.
For pages of size N, you query with ?limit=N+1 and omit the N+1'th
from being displayed. If you get N+1 results, then you can display a
'next page' button. If it's selected, your startkey parameter is the
N+1'th key. To paginate correctly when your view has more than one row
for the same key, look at startkey_docid and endkey_docid.

Afaik, couchdb does not provide you with the information you need to
paginate correctly in the manner you describe. Other b-tree
implementations could give the number of rows between startkey/endkey
efficiently, and other databases could provide a Cursor that would
show you the results as of a point in time. CouchDB does neither.


On 2 April 2011 07:44, Nils Breunese <> wrote:
> If you set the reduce function of your view to '_count' you will get  
> the number of items. Query with ?reduce=false if you want to get the  
> items instead of just the count.
> See for  
> more info on built-in reduce functions.
> Nils.
> ________________________________________
> Van: Andrew Stuart (SuperCoders) []
> Verzonden: zaterdag 2 april 2011 7:27
> Aan:
> Onderwerp: Need to get total rows of startkey/endkey range for paging
> Hey there folks
> I am issuing a query to a view which uses startkey and endkey to
> constrain the range of values to be retrieved from the view.  Within
> this I am using skip and limit to page through the results.
> The problem is that I need the count of the number of total rows, not
> of the view, but of the range defined by startkey and endkey.
> This is needed because I am putting the data into a paging grid, and
> the paging grid needs to know the total rows so it knows how big to
> make the grid and so it knows where the bottom is.
> If you are interested here is a sample query:
> Views do of course return the total number of items in the view, but I
> need not the total items in the view but the total items in the
> startkey/endkey range.
> Can anyone suggest if this is possible?
> thanks
> ------------------------------------------------------------------------
> ------------------------------------------------------------------------
Message  protected by MailGuard: e-mail anti-virus, anti-spam and  
content filtering.
Click here to report this message as spam:

View raw message