Pagination over results can be achieved by using the
skip and limit parameters. For
example, to get the first 10 records from the view:
?limit=10The next ten records can obtained by specifying:
?skip=10&limit=10
On the server, the skip option works by
executing the query and literally iterating over the specified
number of output records specified by skip,
then returning the remainder of the data up until the specified
limit records are reached, if the
limit parameter is specified.
When paginating with larger values for skip,
the overhead for iterating over the records can be significant.
A better solution is to track the document id output by the
first query (with the limit parameter). You can
then use startkey_docid to specify the last
document ID seen, skip over that record, and output the next ten
records.
Therefore, the paging sequence is, for the first query:
?startkey="carrots"&limit=10Record the last document ID in the generated output, then use:
?startkey="carrots"&startkey_docid=DOCID&skip=1&limit=10
When using startkey_docid you must specify the
startkey parameter to specify the information
being searched for. By using the startkey_docid
parameter, Couchbase Server skips through the B-Tree index to
the specified document ID. This is much faster than the
skip/limit example shown above.