1

I am using the following code to get the list of documents using pagination. The code is working fine. But how do I find the continuation token if I want to send it from the client for pagination.

function queryCollectionPaging() {  
return new Promise((resolve, reject) => {
    function executeNextWithRetry(iterator, callback) {         
        iterator.executeNext(function (err, results, responseHeaders) {
            if (err) {
                return callback(err, null);
            }
            else {
                documents = documents.concat(results);
                if (iterator.hasMoreResults()) {
                    executeNextWithRetry(iterator, callback);
                }
                else {
                    callback();
                }
            }
        });
    }

    let options = {
        maxItemCount: 1,
        enableCrossPartitionQuery: true
    };

    let documents = []
    let iterator = client.queryDocuments( collectionUrl, 'SELECT r.partitionkey, r.documentid, r._ts FROM root r WHERE r.partitionkey in ("user1", "user2") ORDER BY r._ts', options);

    executeNextWithRetry(iterator, function (err, result) {
        if (err) {
            reject(err)
        }
        else {
            console.log(documents);
            resolve(documents)
        }
    });
});

};

0

1 Answer 1

1

You could find the continuation token in the responseHeaders parameter, please try to use responseHeaders ['x-ms-continuation'] to grab it.

Such as :

continuationToken = responseHeaders ['x-ms-continuation'];

Then you could pass the token as a parameter to the execute method.

let options = {
        maxItemCount: 1,
        enableCrossPartitionQuery: true,
        continuation : continuationToken
    };

If the continuationToken is null, it means no more results.

You could refer to my previous case: How to get & set Cosmos Db continuation token in javascript.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.