Currently engaged in the development of a web application using MongoDB, which dynamically populates pages with content on the browser.
Familiar with two different methods for paging (referenced here: ):
1) Utilizing .skip() + .limit()
2) Implementing
.find({_id > last_id}).limit(n)
Acknowledging the performance challenges associated with the first approach, it was immediately ruled out.
The second method proves to be effective but only when results are sorted by the _id
field. Sorting by a non-unique field like Date might exclude some documents due to potential duplicates.
In addition, users must navigate through pages sequentially as a variable such as last_id
needs continuous updating based on the _id
of the final document on the previous page. Skipping from page 1 to 7 might lead to page 7 displaying results meant for page 2 because the last_id
retains the _id
value from the last item on page 1.
Hence, the query remains - how can one execute paging when sorting by a non-unique column (e.g., Date or firstName) and facilitate users' ability to jump multiple pages simultaneously?
Any suggestions would be highly valued and appreciated. Thank you!