Atlas Database Triggers run server-side logic when data changes in a connected MongoDB Atlas cluster. They can automate synchronization, logging, notifications, and document updates without a separate application server. They are an Atlas feature, not a feature of the core MongoDB server. section 19.0 section 12.5
A database trigger watches changes through a change stream and passes each matching event object to its linked function. It can watch a collection, a database, or an entire cluster. Unlike a SQL trigger running on the database server, its function runs on a separate serverless layer that scales independently. section 19.2.1
To configure a trigger for automatic embedding updates in the Atlas UI:
- Open Services → Triggers, create a trigger, and select the cluster, sample_mflix database, and embedded_movies collection. section 12.5
- Select Insert, Update, and Replace Document; enable Full Document so the function can read the changed document. section 12.5
- Add a JavaScript function that uses the change event to generate or update the document’s embedding. Configure its logic for the document changes it should handle. section 12.5
Keep an embedding current
Insert a document containing a plot into embedded_movies, then query that document to check for its plot_embedding field. The example uses an external embedding model, such as the OpenAI embeddings API, to produce the vector. section 12.5
Choose operations deliberately; $match can filter change events, while $project can restrict event data. Atlas limits database triggers according to cluster size and its change-stream limit, though triggers on the same collection share one stream. Scheduled and authentication triggers handle different kinds of events. section 19.2.1
