0

I have the following requirement i want to capture record from cosmosDB and push it to blog storage.

This above problem i have solved with azure function cosmos DB trigger (that will capture any changes made to record in cosmos DB container).

How to capture full load?

requirement is i have to get all the record from cosmos DB container and push it to blog storage.

so the problem is cosmosDB trigger only capture if there is some change in record, so how i can achieve this full load.

For Full load i have create one python script also.

Reference: https://github.com/Azure/azure-cosmos-python

Reference Script: How To Update Record in Cosmos Db using python?

query_data = client.QueryItems(collection_link,
                                   'SELECT * FROM ' + COSMOS_DB_COLLECTION_ID,
                                   {'enableCrossPartitionQuery': True})
    for item in query_data:
        client.ReplaceItem(item['_self'], item, options=None)

so what actual my script is doing its taking all record and i am calling ReplaceItem for each record, but what i observed is azure function cosmos DB trigger won't capture changes of all record its capture few record only.

so is there problem with the script?

Mohit Singh
  • 401
  • 1
  • 10
  • 30
  • You're requirement here isn't exactly clear. A cosmos db trigger will fire on any changes to documents within your DB. If you want to copy the entire contents of the DB into blob storage then you'll need some other solution. – Tom Biddulph Jul 13 '20 at 10:11

1 Answers1

0

First, I think client dont have 'QueryItems'.

Second, there is no changed in your document.

You should do like below:

url = os.environ['ACCOUNT_URI']
key = os.environ['ACCOUNT_KEY']
client = cosmos_client.CosmosClient(url, {'masterKey': key})
database_name = "testbowman"
container_name = "testbowman"
database = client.get_database_client(database_name)
container = database.get_container_client(container_name)
for item in container.query_items('SELECT * FROM c', enable_cross_partition_query=True):
    logging.info("This is Query database!" + json.dumps(item))
    item['Description'] = "!!!!!!!!!!!!!!"
    container.replace_item(item['id'],item)
Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • as you said that there is no changed in my document. but i noticed that if i don't update the document as i am doing in the above script still azure cosmos DB trigger will capture few record.. any idea why. may be because of _ts field? – Mohit Singh Jul 14 '20 at 14:19