Search⌘ K
AI Features

Overview of Triggers

Explore how to implement triggers in Cosmos DB using JavaScript for server-side programming. Learn the differences between pre-triggers and post-triggers, how to use getRequest and getResponse, and the methods to create and upload triggers via the Azure portal and SDKs. Understand how triggers run before or after document actions and manage their execution within Cosmos DB.

Introduction

Another way we can use the database engine is with triggers. Cosmos DB triggers differ from the ones we can create in traditional SQL databases in two main ways:

  • We can create triggers that run both before and after a document action:

    • Pre-trigger

    • Post-trigger

  • Triggers are not executed automatically.

Definition

Triggers are JavaScript functions that have no input arguments and don’t return a value. We use getRequest() and getResponse() to interact with the engine.

Pre-triggers

...