I have the cosmos db trigger in azure functions and it fires when the document is changed which is fine.
But my document is big and i only need the updated property in the trigger.
I can solve this by comparing the old and new document but in trigger i only get the updated document.
So is there a way to get the old and updated document in trigger.
My Azure Function trigger is
module.exports = async function (context, documents) {
if (!!documents && documents.length > 0) {
context.log('Document Id: ', documents[0].id);
context.log('Document : ', documents[0]);
}
context.done(); }
My Function Bindings are
{ "bindings": [
{
"type": "cosmosDBTrigger",
"name": "documents",
"direction": "in",
"leaseCollectionName": "leases",
"connectionStringSetting": "AzureWebJobsCosmosDBConnectionString",
"databaseName": "ToDoList",
"collectionName": "Items",
"createLeaseCollectionIfNotExists": true
} ], "disabled": false }
Thanks in Advance
There is no way, at this point, to obtain the previous version or to just get the delta.
The Change Feed contains the operation and payload, not a reference to the previous state.
There is an open suggestion @ https://feedback.azure.com You might implement a pattern as stated in above link:
- Store every version/change as a separate item
- Read the change feed to merge/consolidate changes and trigger appropriate actions downstream.
So basically you need another function with a change feed listener that stores every document in a separate "version" collection. Afterwards you can add a CosmosDB binding, that gets the latest version from latter collection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With