MongoDB Update

MongoDB Update

Certified

Update or replace MongoDB documents

Runs MongoDB replaceOne, updateOne, or updateMany on a collection. Defaults to UPDATE_ONE; both filter and document accept BSON maps or strings and are rendered from Flow variables. Requires write access; upserts are not exposed.

Failures

UPDATE_MANY is not atomic: if it fails mid-write (failover, network error, or a failing document such as a duplicate key), some documents may already be updated and the task reports no count. Before retrying, check the update is safe to apply twice: $inc, $push and $mul apply again, and an update that changes a field the filter matches on reaches other documents. To make a retry safe, add "batchId": {"$ne": "{{ execution.id }}"} to the filter and set "batchId": "{{ execution.id }}".

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

Replace a document.

yaml
id: mongodb_update
namespace: company.team

tasks:
  - id: update
    type: io.kestra.plugin.mongodb.Update
    connection:
      uri: "mongodb://root:example@localhost:27017/?authSource=admin"
    database: "my_database"
    collection: "my_collection"
    operation: "REPLACE_ONE"
    document:
      _id:
        $oid: 60930c39a982931c20ef6cd6
      name: "John Doe"
      city: "Paris"
    filter:
      _id:
        $oid: 60930c39a982931c20ef6cd6

Update a document.

yaml
id: mongodb_update
namespace: company.team

tasks:
  - id: update
    type: io.kestra.plugin.mongodb.Update
    connection:
      uri: "mongodb://root:example@localhost:27017/?authSource=admin"
    database: "my_database"
    collection: "my_collection"
    filter:
      _id:
        $oid: 60930c39a982931c20ef6cd6
    document: '{"$set": { "tags": ["blue", "green", "red"]}}'
Installation

Our standard Docker images already include this plugin. If you use a -slim image or another setup, install it with the following command:

kestractl plugins get io.kestra.plugin:plugin-mongodb --compatible-for $KESTRA_VERSION

For kestractl, use your Kestra version with --compatible-for, or specify an exact plugin version.

For Kestra CLI, replace LATEST with a specific version or version range to pin the plugin version.

Properties

MongoDB collection

MongoDB connection properties

Definitions
uri*string

Connection string to MongoDB server

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

MongoDB database

Update payload or replacement document

BSON string or map rendered before execution. An empty $set fails instead of reporting success on a no-op. A null map entry is dropped when the flow is parsed; pass a JSON string when a null is needed, for example '{"$set": {"k": null}}'.

Query filter

BSON string or map rendered before execution; selects documents to update. A null map entry is dropped when the flow is parsed; pass a JSON string when a null is needed, for example '{"deletedAt": null}'.

Assets this task consumes as inputs or produces as outputs, for lineage tracking and the asset graph (Enterprise Edition). A flow declaring this property on a task is rejected in the open-source edition.

Definitions
assetFailureBehaviorstring
Possible Values
IGNOREFAILWARN

Asset failure behavior

Behavior applied to the task state when a declared asset fails to render, emit, or be persisted (e.g. a lock conflict): FAIL escalates it to FAILED, WARN (default) warns it if it would otherwise succeed, IGNORE leaves the state untouched.

enableAutobooleanstring

Whether to auto-register assets referenced dynamically at runtime that are not statically declared in inputs or outputs.

inputsarray

The assets consumed as inputs.

id*string
Min length1
typestring
outputs

The assets produced as outputs.

id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*string
Min length1

Custom asset type

descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
DefaultUPDATE_ONE
Possible Values
REPLACE_ONEUPDATE_ONEUPDATE_MANY

Update operation

One of UPDATE_ONE (default), UPDATE_MANY, or REPLACE_ONE.

The number of documents matched by the query

Null for unacknowledged writes (w=0), which have no counts to report.

The number of documents modified by the update

Null for unacknowledged writes (w=0), which have no counts to report, and on a write concern error, where the driver reports only a matched count and not how many documents were modified.

Upserted document id

Null unless MongoDB created a document during the write. Otherwise the _id of that document, as a string:

  • ObjectId: its hex string
  • String: as is
  • Int32, Int64, Double or Decimal128: the number
  • UUID (Binary subtype 4): its canonical string
  • any other type, including a legacy UUID (Binary subtype 3) or a document: its relaxed MongoDB Extended JSON, such as {"a": 1}

Always null for unacknowledged writes (w=0), which have no id to report.

Whether the write was acknowledged

Unitcount

Number of documents updated in MongoDB