Navigation

Scheduled Triggers

Important

The MongoDB Stitch SDK is deprecated. For guidance on migrating to MongoDB Realm, please see Migrate Your App from Stitch to Realm.

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 Stitch UI:

  1. Click Triggers under MongoDB Cluster in the left-hand navigation.
  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.
../_images/trigger-example-scheduled.png

To create a scheduled trigger with stitch-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 Stitch CLI. All imported scheduled trigger configurations must specify a CRON expression.

  2. Import the application directory into your application.

    stitch-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 Stitch 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 Stitch uses to determine when to fire the trigger.