Trigger
← Back to DP-420 Terminology Reference
Category: Server-Side Programming
Summary: Pre- or post-operation JavaScript logic, explicitly invoked by the client per request.
Overview
A trigger is server-side JavaScript logic in Azure Cosmos DB for NoSQL that executes automatically before (pre-trigger) or after (post-trigger) a specified operation (such as an item creation), enabling validation, modification of the request, or automated follow-up actions without requiring explicit calls from client code — though the client must still explicitly specify which trigger to invoke on a given request.
More Info & Links
DP-420 Style Practice Questions
Q1. What is the difference between a pre-trigger and a post-trigger in Azure Cosmos DB?
- A. A pre-trigger runs before an operation completes; a post-trigger runs after it completes
- B. A pre-trigger only works with queries; a post-trigger only works with point operations
- C. A pre-trigger disables indexing; a post-trigger enables it
- D. There is no difference
Q2. Must a client explicitly specify which trigger to invoke on a request?
- A. Yes, triggers must be explicitly specified per request; they don't fire automatically
- B. No, all triggers fire automatically for every operation
- C. Only pre-triggers require explicit specification
- D. Only post-triggers require explicit specification
Answer Key
Answers are listed at the very end so you can attempt the questions first.
- Q1 (Trigger): A. A pre-trigger runs before an operation completes; a post-trigger runs after it completes — Pre-triggers execute before the target operation; post-triggers execute after the operation has completed.
- Q2 (Trigger): A. Yes, triggers must be explicitly specified per request; they don't fire automatically — Unlike some database triggers, Azure Cosmos DB triggers must be explicitly requested by the client for each applicable operation.
DP-420: Designing and Implementing Cloud-Native Applications Using Microsoft Azure Cosmos DB — term detail page