Triggers Overview
On this page
Realm Triggers execute application and database logic. Triggers can respond to events or use pre-defined schedules.
Triggers listen for events of a configured type. Each Trigger links to a specific Realm Function. When a Trigger observes an event that matches your configuration, it "fires." The Trigger passes this event object as the argument to its linked Function.
A Trigger might fire on:
- A specific operation type in a given Collection.
- An authentication event, such as user creation or deletion.
- A scheduled time.
Realm keeps track of the latest execution time for each Trigger.
Trigger Types
MongoDB Realm supports three types of triggers:
- Database triggers respond to document insert, changes, or deletion. You can configure Database Triggers for each linked MongoDB collection.
- Authentication triggers respond to user creation, login, or deletion.
- Scheduled triggers execute functions according to a pre-defined schedule.
Limitations
Realm Function Constraints Apply
Triggers invoke Realm Functions. This means they have the same constraints as all Realm Functions.
Maximum Executions Per Second
MongoDB Realm limits the execution of Trigger Functions. A Trigger can execute up to 2500 times per second. When a Trigger calls a Function, this call goes into a queue. When capacity becomes available, Realm executes the Function call.
Your application's execution rate may be lower than 2500 per second. This varies depending on your Atlas instance size.
Database Triggers with event ordering work differently. Each ordered Trigger processes events in sequence. Realm waits for each event execution in the sequence to complete. Then, it handles the next event. Only one sequence for a given ordered Trigger executes at a time.
Number of Triggers Cannot Exceed Available Change Streams
MongoDB Realm limits the total number of Database Triggers. The size of your Atlas cluster drives this limit.
Each Atlas cluster tier has a maximum number of supported change streams. A Database Trigger requires its own change stream. Other Realm services also use change streams, such as Realm Sync. Database Triggers may not exceed the number of available change streams.
Learn more about the number of supported change streams for MongoDB Atlas tiers.