0PricingLogin
MongoDB Academy · Lesson

Scheduled Triggers and Cron Jobs

Learners will configure a scheduled trigger with a cron expression to run periodic maintenance tasks like archiving old documents.

What Are Scheduled Triggers?

Scheduled Triggers in Atlas App Services execute an Atlas Function on a recurring schedule defined by a cron expression. Unlike database triggers (which fire in response to data changes), scheduled triggers fire based on time — making them ideal for maintenance tasks, periodic reports, data archiving, and cache refreshes that need to run automatically without human intervention.

Cron Expression Syntax

Atlas scheduled triggers use standard five-field cron expressions: minute hour day-of-month month day-of-week. Use * for 'every', */n for 'every n units', comma-separated values for lists, and ranges with -. Examples: 0 * * * * = every hour on the hour; 0 2 * * * = daily at 2 AM; */15 * * * * = every 15 minutes.

// Common cron expressions
'0 * * * *'    // Every hour at minute 0
'0 2 * * *'    // Daily at 02:00 UTC
'0 0 * * 0'    // Every Sunday at midnight
'0 0 1 * *'    // First day of every month at midnight
'*/15 * * * *' // Every 15 minutes
'0 9-17 * * 1-5' // Every hour, 9 AM to 5 PM, weekdays

All lessons in this course

  1. Database Triggers: Reacting to CRUD Events
  2. Scheduled Triggers and Cron Jobs
  3. Writing Atlas Functions in JavaScript
  4. HTTPS Endpoints as Lightweight Webhooks
← Back to MongoDB Academy