The CouchDB HTTP API provides many features for efficient paging.
The simplest method will use startkey and count . Count is the maximum number of entries that CouchDB will return for this request, something that depends on your design, and startkey is where you want to launch CouchDB. When you request a submission, he will also tell you how many records there are, which allows you to calculate how many pages there will be if you want to show it to users.
Thus, the first request will not indicate a start key, but only a count of the number of records that you want to show. You can then mark the key of the last returned record and use it as a start key for the next page. In this simple form, you get an overlap where the last entry of one page is the first of the following. If this is undesirable, it is trivial to simply not display the last page entry.
An easier way to do this is to use the skip option to design the source document for the page, but use this method with caution. The skip parameter simply causes the internal engine not to return the records that it iterates. Although this gives the desired behavior, it is much slower than finding the first document for a page by key. The more documents skipped, the slower the request.
Kerr Nov 24 '08 at 15:46 2008-11-24 15:46
source share