1
votes

I created a trigger on a cosmosdb to azure function in azure, I couldn't find anything in documents how to distinguish between delete, update and create

{
  "bindings": [
    {
      "type": "cosmosDBTrigger",
      "name": "input",
      "direction": "in",
      "leaseCollectionName": "leases",
      "connectionStringSetting": "pcmDevValidAppsTrigger_ConnectionString",
      "databaseName": "pcmobile-dev",
      "collectionName": "validApps",
      "createLeaseCollectionIfNotExists": true
    }
  ]
}
module.exports = async (context, documents) => {
    context.log('Document Id: ', documents[0].id);
}

1

1 Answers

2
votes

You cannot, as per the documentation: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-trigger - the Trigger consumes the Change Feed, and the Change Feed currently only includes inserts and updates (https://docs.microsoft.com/en-us/azure/cosmos-db/change-feed#features-of-change-feed):

The change feed includes inserts and update operations made to items within the container. You can capture deletes by setting a "soft-delete" flag within your items (for example, documents) in place of deletes. Alternatively, you can set a finite expiration period for your items with the TTL capability. For example, 24 hours and use the value of that property to capture deletes. With this solution, you have to process the changes within a shorter time interval than the TTL expiration period.