MongoDB Trigger

MongoDB Trigger

Certified

Poll MongoDB and trigger on results

Periodically runs a MongoDB find; if results are non-empty, starts a Flow with the rows or stored file. Uses Find task behavior (filter/projection/sort/limit/skip). Default interval is 60s and store is false, returning rows in trigger output.

By default, every poll that returns documents starts an execution, including for documents an earlier poll already delivered. Set watermarkField to deliver each document once.

yaml
type: io.kestra.plugin.mongodb.Trigger

Wait for a MongoDB query to return results, and then iterate through returned documents.

yaml
id: mongodb_trigger
namespace: company.team

tasks:
  - id: each
    type: io.kestra.plugin.core.flow.ForEach
    values: "{{ trigger.rows }}"
    tasks:
      - id: return
        type: io.kestra.plugin.core.debug.Return
        format: "{{ fromJson(taskrun.value) }}"

triggers:
  - id: watch
    type: io.kestra.plugin.mongodb.Trigger
    interval: "PT5M"
    connection:
      uri: mongodb://root:example@localhost:27017/?authSource=admin
    database: samples
    collection: books
    filter:
      pageCount:
        $gte: 50
    sort:
      pageCount: -1
    projection:
      title: 1
      publishedDate: 1
      pageCount: 1

Deliver each new or updated order once, using its updatedAt field as the watermark.

yaml
id: mongodb_trigger_watermark
namespace: company.team

tasks:
  - id: each
    type: io.kestra.plugin.core.flow.ForEach
    values: "{{ trigger.rows }}"
    tasks:
      - id: log
        type: io.kestra.plugin.core.log.Log
        message: "{{ taskrun.value }}"

triggers:
  - id: watch
    type: io.kestra.plugin.mongodb.Trigger
    interval: "PT1M"
    connection:
      uri: "{{ secret('MONGODB_URI') }}"
    database: shop
    collection: orders
    filter:
      status: paid
    watermarkField: updatedAt
    limit: 500
Properties
Defaultfalse

Specifies whether a trigger is allowed to start a new execution even if a previous run is still in progress.

Collection name

MongoDB connection

Definitions
uri*string

Connection string to MongoDB server

URL format like mongodb://mongodb0.example.com: 27017

Database name

Query filter

BSON string or map rendered before execution.

DefaultPT1M
Formatduration

Polling interval

Duration between queries; defaults to PT60S.

Limit

Maximum documents returned.

Projection

BSON string or map selecting fields to return.

Skip

Documents to skip before returning results.

Sort

BSON string or map defining sort order.

SubTypestring
Possible Values
CREATEDSUBMITTEDRUNNINGPAUSEDRESTARTEDKILLINGSUCCESSWARNINGFAILEDKILLEDCANCELLEDQUEUEDRETRYINGRETRIEDSKIPPEDBREAKPOINTRESUBMITTED

List of execution states after which a trigger should be stopped (a.k.a. disabled).

Defaultfalse

Store results

When true, writes results as Ion to internal storage; otherwise rows are kept in output. Defaults to false.

Watermark field

Field used to deliver each document only once, such as updatedAt, a sequence number or _id. A dotted path reaches a nested field. When set, the trigger stores the position of the last delivered document in the namespace KV Store and only returns the documents after it, read in the order of this field and then _id; limit caps how many each poll returns. It can't be combined with sort or skip. Use a field whose value only increases when a document is added or updated, with a single type across documents: a document written later with a lower value is never returned, nor is one whose value has another type than the stored position (a string among dates, for example). ObjectId _id values are only ordered to the second across clients. Documents where the field is missing or null are never returned. On a large collection, create an index on the fields filter matches by equality, then this field, then _id (for example {status: 1, updatedAt: 1, _id: 1}), so that each poll doesn't scan and sort the whole collection; _id alone needs no extra index. When not set, every poll that returns documents starts an execution, including for documents an earlier poll already delivered.

Defaulttrue

A condition that determines whether the trigger should run.

A Pebble expression evaluated at trigger time. The trigger fires only when the expression evaluates to a truthy value (true, a non-empty string, a non-zero number). Use this to gate trigger execution on dynamic runtime values such as execution labels, flow variables, or environment conditions.

Result rows

Present when store is false.

Rows fetched

Formaturi

Stored result URI

Internal storage URI when store is true.