Azure / azure-cosmosdb-node

We recently announced deprecation of JS v1 SDK and this repo. Starting September 2020 Microsoft will not provide support for this library. Existing applications using library will continue to work as-is. We strongly recommend upgrading to @azure/cosmos library.
https://github.com/Azure/azure-sdk-for-js
MIT License
141 stars 108 forks source link

Implement the pagination using continuation token with cross partition #221

Closed yingting2017 closed 6 years ago

yingting2017 commented 6 years ago

Use-Case: Let’s say user wants to access 10 records starting from 100th index (order by query may change based on timestamp, city or name etc.).

So, one way is to set the page size as 10 (this can any fixed number) and then make a call to the queryDocuments(collectionLink, sqlQuery, feedOptions) API. In the response of this API, we get the FeedResponse and using fetchNextBlock() API of FeedResponseI just need to jump to the 100th index in 10 iterations (in our case) and in turn return the next desired block to the user. The problem with this approach is to iterate the records multiple times which I don’t want as this nth index can be any big number.

The other way is to set the page size 100 (staring index given by user) and then make a call to the queryDocuments(collectionLink, sqlQuery, feedOptions). In the response of this API, we get the FeedResponse and using the get ContinuationToken() API of FeedResponse, I get the token. I’ll use this token to construct the FeedOptions again and then pass it to queryDocuments(collectionLink, sqlQuery, feedOptions) API to get the final results.

srinathnarayanan commented 6 years ago

Hi @yingting2017 , I am little unclear on the question. Are you asking which method we would recommend for your use case? The second method would be faster and consume lesser RUs on the whole.

srinathnarayanan commented 6 years ago

I am closing this as the initial query has been addressed. Please feel free to reopen it if you have any followup. Thanks!