Auditing Cosmos DB data using change feed triggers

Many of you might have already heard about Cosmos DB, as it has become very popular and many organizations are using it because of the features it provides.

In this recipe, we will learn about integrating serverless Azure Functions with a serverless NoSQL database in Cosmos DB. You can read more about Cosmos DB at https://docs.microsoft.com/en-us/azure/cosmos-db/introduction.

Often, it might be necessary to keep change logs of fields, attributes, documents, and more for auditing purposes. In the world of relational databases, you might have seen developers using triggers or stored procedures to implement this kind of auditing functionality, where you write code so that you can store data in a separate audit table.

In this recipe, we will learn how easy it is to achieve the preceding use case and audit Cosmos DB collections by writing a simple function that gets triggered whenever there is a change in a document of a Cosmos DB collection.

In the world of relational databases, a collection is the same as a table, and a document is the same as a record.