[QUERY] How to paginate without using maxItemCount?
See original GitHub issueQuery/Question In the documentation [1] it is written:
The maxItemCount property shouldn’t be used just for pagination purpose. It’s main usage it to improve the performance of queries by reducing the maximum number of items returned in a single page.
We use pagination in the following way:
When we do a query, we set the maxItemCount
according to the requested result size. We only take the first feed response in the returned flux. From this, we return the result list and also the continuation-token. With this information, we/the user can get the subsequent pages by doing a second query while using the continuation-token in the request.
But according to the documentation, our technique is wrong. The question is: How to do it correctly?
As a side note: Our query orders the results. Therefore we can not work with an OFFSET LIMIT
clause for pagination. If we do this and there were new items inserted that would have been part of the first page that was already requested, we would get results on the second page that already were given on the first page. This is no problem when paging using the continuation-token as described above.
[1] https://docs.microsoft.com/de-de/azure/cosmos-db/performance-tips#sdk-usage
Setup (please complete the following information if applicable):
- OS: Linux
- IDE : IntelliJ
- Version of the Library used: CosmosDB-SDK v3.5
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
lol, I am sure I pasted it 😛 Here you go - https://github.com/Azure-Samples/azure-cosmos-java-getting-started This sample project has both sync and async examples.
@kushagraThapar thank you for the hint!
CosmosPagedFlux
andbyPage(continuationToken, pageSize)
was exactly was we needed.You mentioned some examples but it looks like the link is missing. We were able to restore our paging functionality but seeing a few more examples of how to use
CosmosPagedFlux
andCosmosPagedIterable
correctly would be helpful for the future.