O'Reilly logo

Learning Azure DocumentDB by Riccardo Becker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building triggers

A trigger is application logic or a business rule that is written in JavaScript. It looks similar to a function or method, but a trigger is only executed by the database engine when a document gets inserted, replaced, or deleted. Triggers can be useful, for example, to create an audit trail to keep track of all the changes in the system or to set default values for a document to be created.

The example trigger is a trigger that is fired before the actual insert (although triggers and their actual insert, replace, or delete actions on a document are inside one transaction) and checks for the first name. If it is not there or empty, it will set a default value. To test the trigger, we will also create a new property on the document ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required