Details
-
New Feature
-
Resolution: Won't Fix
-
Minor - P4
-
None
-
3.4.2
-
None
Description
For large amounts of documents it is not performant to use page-based paging with skip and limit.
Then it is better to use cursor based paging.That means you query by any attribute sorted and remember the value of the sorted field of the last document you found and give it to the client.
If the user in the client clicks on "next", you send the last value to the backend and query with a $gt-operator.
Here is an article which explains the idea in detail:
https://www.sitepoint.com/paginating-real-time-data-cursor-based-pagination/
The problem is, that you have to implement a lot to support that.Inside the java api it could be implemented much easier.
api-suggestion:
MongoCursor<DocumentWithPagingInfo> cursor = collection.findPagable()
The Class DocumentWithPagingInfo has two methods:
getDocument() and getPagingKey()
The pagingKey is a string, which encodes the informations about the used filter and sorting and the actual values of the filtered values.
This string can be given to the client. And if it passed it to the server application, the server application would call a new method collection.findWithPagingKey(String pagingKey)
Perhaps the api could be done better.
You also might ask, why that could not be implemented outside of the framework:
The pagingcursor must encapsule the filter sort and the actual values. These informations are all known inside the api. Outside it is not possible to implement a generic solution, because outside you cannot get these informations from a query-Object (it is a builder pattern).