MongoDB Change Stream

Watches a MongoDB database for real-time change events and emits each change document as a JSON event.

Configuration

- mongodb_change_stream:
    name: watch_orders
    credentials_path: /etc/mongodb/credentials.json
    db_name: my_database

Fields

FieldTypeDefaultDescription
namestringrequiredTask name.
credentials_pathstringPath to MongoDB credentials file. Omit to connect to localhost:27017 without authentication. See Credentials.
db_namestringrequiredDatabase name to watch for changes.
depends_onlistUpstream task names.
retryobjectRetry configuration.

Output

FormatCrateDescription
JSONmongodbThe fullDocument from each change stream event, converted to JSON. Event ID is set to the document’s _id.

Behaviour

The change stream watches the entire database for document inserts, updates, and replacements. Only operations that include a fullDocument are emitted. If a change event lacks a full document (e.g., unset fullDocument for pre- and post-images), the operation is skipped.

The stream reconnects automatically on connection loss using an infinite retry loop with exponential backoff and jitter.