Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination based on continuation token #14

Open
rkganji opened this issue Sep 1, 2020 · 0 comments
Open

Pagination based on continuation token #14

rkganji opened this issue Sep 1, 2020 · 0 comments

Comments

@rkganji
Copy link

rkganji commented Sep 1, 2020

We have a requirement for clients to get results in paginated way. Pagination was implemented as below:

final CosmosQueryRequestOptions options = new CosmosQueryRequestOptions();
options.setResponseContinuationTokenLimitInKb(2);
options.setQueryMetricsEnabled(true);
        
// Retrieve the documents response using DocumentClient.
Iterable<FeedResponse<Reservation>> feedResponseIterator = container
                .queryItems(query, options, Reservation.class)
                .iterableByPage(continuationToken, 50);
List<Object> docsList = new ArrayList<>();
ResponseWithHeaders result = new ResponseWithHeaders();
FeedResponse<Reservation> page = feedResponseIterator.iterator().next();
String nextToken = page.getContinuationToken();
docsList.addAll(page.getResults());

Issue:
This is working fine when overall result set is less e.g., 120 documents returned as 3 pages. This is not working fine when overall results set is large. When total no. of documents is ~1000, same continuationToken is being returned causing an endless loop and not able to get documents beyond initial 50 docs returned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant