Skip to content

Pagination based on continuation token #14

@rkganji

Description

@rkganji

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions