question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUERY] How to paginate without using maxItemCount?

See original GitHub issue

Query/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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kushagraThaparcommented, May 7, 2020

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.

0reactions
tomekapccommented, May 7, 2020

@kushagraThapar thank you for the hint! CosmosPagedFlux and byPage(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 and CosmosPagedIterable correctly would be helpful for the future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tips & Tricks for Query Pagination in Azure Cosmos DB
Run the query with MaxItemCount = 10; If n results are returned from the query and n < 10, repeat the query with...
Read more >
Pagination in Cosmos DB using Page Size and Page Number
var query = Client.CreateDocumentQuery<T>( UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId), new FeedOptions { MaxItemCount = ...
Read more >
Paging Azure Cosmos DB Query Results from .NET
Learn how to create a simple forward only query resultset by Paging Azure Cosmos DB Query Results using the .NET SDK.
Read more >
Paging through query results in Azure DocumentDB
Pass in a FeedOptions instance to the CreateDocumentQuery() method with the MaxItemCount property set. · Use the AsDocumentQuery() extension ...
Read more >
Paginate cross-product query results with the Azure Cosmos ...
Paginate cross-product query results with the Azure Cosmos DB SQL API SDK ... If you have not already cloned the lab code repository...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found