Navigation

Scheduled Triggers

Overview

Scheduled Triggers allow you to execute server-side logic on a regular schedule that you define. You can use scheduled Triggers to do work that happens on a periodic basis, such as updating a document every minute, generating a nightly report, or sending an automated weekly email newsletter.

Create a Scheduled Trigger

To create a scheduled Trigger in the Realm UI:

  1. Click Triggers under MongoDB Cluster in the left navigation menu.
  2. Select Scheduled Triggers from the Trigger type dropdown menu.
  3. Click Add a Trigger to open the Trigger configuration page.
  4. Enter configuration values for the Trigger. You can configure two types of Trigger schedules: Basic or Advanced.
    • A Basic schedule executes the Trigger periodically based on a single unit of time and an interval, such as “every five minutes” or “every Monday”.
    • An Advanced schedule executes the Trigger based on a custom CRON expression that you define.
  5. Click Save.
Creating a Trigger in the Realm UI.

To create a scheduled Trigger with realm-cli:

  1. Add a scheduled Trigger configuration file to the triggers subdirectory of a local application directory.

    Note

    You cannot create a Trigger that runs on a Basic schedule using Realm CLI. All imported scheduled Trigger configurations must specify a CRON expression.

  2. Import the application directory into your application.

    realm-cli import
    

Reference

Scheduled Trigger Configuration

Scheduled Triggers have the following configuration parameters:

Scheduled Trigger configuration files have the following form:

/triggers/<triggers name>.json
{
   "type": "SCHEDULED",
   "name": "<Trigger Name>",
   "function_name": "<Trigger Function Name>",
   "config": {
     "schedule": "<CRON expression>"
   },
   "disabled": <boolean>
}
Field Description
Trigger Type
type: <string>

Required. The type of the Trigger.

For scheduled Triggers, this value should be set to SCHEDULED.

Trigger Name
name: <string>
Required. The name of the Trigger.
Linked Function
function_name: <string>

Required. The name of the Realm Function that the Trigger executes whenever it fires.

Note

A scheduled Trigger does not pass any arguments to its linked Function.

Schedule
config.schedule: <string>
Required. The CRON expression that MongoDB Realm uses to determine when to fire the Trigger.