User-defined functions and triggers

To extend the query language, you can write your own user-defined function (UDF) and in your queries. Note that you cannot use these in Stored Procedures. UDFs are used to extend the SQL query language in Azure Cosmos DB and can be only called from inside queries. Triggers, however, are divided into two categories:

  • Pre-triggers
  • Post-triggers

Additionally, you can select an operation that this trigger refers to:

  • All
  • Create
  • Delete
  • Replace

Here you can find an example of a trigger that updates a timestamp in a document before it is created:

var context = getContext();var request = context.getRequest();var documentToCreate = request.getBody();if (!("timestamp" in documentToCreate)) { var ts = new Date(); ...

Get Hands-On Azure for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.