How do I set continuation tokens for Cosmos DB queries sent by document_client objects in Python?

后端 未结 3 1180
一个人的身影
一个人的身影 2021-01-26 23:03

I have an API that retrieves documents based on keywords that appear in document fields. I would like to paginate results so that I can return documents to a client sending a re

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-26 23:26

    It turns out that the query results needed to be handled from the results object itself, and the method _fetch_function(options) should be called:

    q = client.QueryDocuments(collection_link, query, {'maxItemCount':10})
    results_1 = q._fetch_function({'maxItemCount':10})
    #this is a string representing a JSON object
    token = results_1[1]['x-ms-continuation']
    results_2 = q._fetch_function({'maxItemCount':10,'continuation':token})
    

    The data is contained in results_[n][0] and header information returned from the call is returned in results_[n][1].

提交回复
热议问题