Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting update and deletion in Cosmos DB using CosmosDbTrigger in an Azure Function

I'm trying to work my way around DB notifications for document events in an Azure Function using CosmosDBTrigger.

I get notified for inserts and updates, however there is no notification for deletion. Is there any way to have it triggered or by design such type of events are not expected? (eg, event sourcing)

In case of an update, is there any way to check if it is an insert or an update? Maybe looking at the ETag?

like image 535
Horia Toma Avatar asked Dec 24 '22 10:12

Horia Toma


1 Answers

There are no deletes in Cosmos DB change feed, so Functions aren't triggered either:

The change feed includes inserts and update operations made to documents within the collection. You can capture deletes by setting a "soft-delete" flag within your documents in place of deletes

And there's no insert/update attribute available out-of-the-box, they suggest you do that on application level:

There is no system property yet. However, you can add an attribute to the document, to do a soft update by updating the document attribute.

Both from quotes are from Working with the change feed support in Azure Cosmos DB

like image 137
Mikhail Shilkov Avatar answered May 05 '23 02:05

Mikhail Shilkov