CosmosDbTrigger filtered for only inserts?

Viewed 461

I've got a really simple azure Function with a CosmosDbTrigger set up (taken nearly straight from the examples just as a minimal repro):

[FunctionName("ProcessEmail")]
public static void Run([CosmosDBTrigger("mydb", "mycollection")]IReadOnlyList<Document> documents, TraceWriter log)
{
    log.Verbose("Documents modified " + documents.Count);
    log.Verbose("First document Id " + documents[0].Id);
}

This was super simple to set up and works perfectly.

However, in my case I am only interested in being notified when a record is inserted - not when it is updated.

  1. Is it possible to have the trigger only occur when a document is inserted?
  2. If not, is it possible to tell, per-document, whether it was an insertion or an update that triggered this run?
  3. If not, what's my best option here? Have a flag on the document for whether or not this phase of it has been processed?
1 Answers

We had a similar requirement for an update-only CosmosDB trigger in one of our function apps. However, we ended up using a flag since controlling the change feed is not yet supported according to the docs.

Today, you see all operations in the change feed. The functionality where you can control change feed, for specific operations such as updates only and not inserts is not yet available. You can add a “soft marker” on the item for updates and filter based on that when processing items in the change feed.

Related