I am trying to extract historical data from a CosmosDB container using Azure Python SDK. I want to implement pagination when using query_items_change_feed(). I tried specifying max_item_count in the arguments. But it does not seem to follow the specified value. There are no proper documentation on this method for Python SDK.
Is it possible to implement pagination using Azure Python SDK? If yes, how do we implement it?
Code snippet:
Tested this on sample container with 1000 documents. This code created 20 json files with documents data in each files respectively. I notice that while uploading the 1000 documents to the container, it was uploaded like 60, 40, 39, 60, ... and JSON files sizes are also exactly in the same order. Why does this behaviour occur?
with cosmos_client.CosmosClient(self.HOST, self.MASTER_KEY) as client:
db = client.get_database_client(database=DATABASE_ID)
container = db.get_container_client(container=CONTAINER_ID)
change_feed_iterator = container.query_items_change_feed(
is_start_from_beginning=True,
max_item_count=5,
partition_key_range_id=0
)
i=1
page = change_feed_iterator.__iter__()
for item_page in change_feed_iterator.by_page():
try:
json.dump(list(item_page), open(f"batch_data/batch_data_test/_{i}.json", "w"), indent=4)
i+=1
except StopIteration:
break