I'm creating a page system using CouchDB, showing:
- 10 items per page
- a link to the previous page (if any)
- a link to the next page (if any)
From this article on the topic, I understand that using skip
is suboptimal, and that I should instead use the startkey
property to specify the first document, read 11 documents from there, display the first 10 and use the key of the 11th to display the link to the next page. What troubles me is the link to the previous page. The article says:
Populating the link to the previous page is as simple as carrying the current startkey over to the next page. If there’s no previous startkey, we are on the first page.
This works when going to the next page: when I move from page 4 to page 5 I can remember that the previous page was 4. But when I move back from page 5 to page 4, I have no way of carrying over the startkey
of page 3. How can this work?
Is it possible (and recommended) to use endkey
along with skip=10
and limit=1
to find the first element on the previous page, so that I may create a link back to it?