MongoDB InsertOne

MongoDB InsertOne

Certified

Insert one document into MongoDB

Renders a BSON document from Flow variables and inserts it with insertOne. Requires write access; document may be provided as JSON/BSON string or map.

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

Insert a document with a map.

yaml
id: mongodb_insertone
namespace: company.team

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

Insert a document from a JSON string.

yaml
id: mongodb_insertone
namespace: company.team

tasks:
  - id: insertone
    type: io.kestra.plugin.mongodb.InsertOne
    connection:
      uri: "mongodb://root:example@localhost:27017/?authSource=admin"
    database: "my_database"
    collection: "my_collection"
    document: "{{ outputs.task_id.data | toJson }}"
Properties

MongoDB collection

MongoDB connection properties

Definitions
uri*string

Connection string to MongoDB server

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

MongoDB database

Document to insert

BSON string or map rendered before execution. A null map entry is dropped when the flow is parsed; pass a JSON string when a null is needed, for example '{"_id": 1, "k": 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

Inserted document id

The _id of the inserted 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}

With an unacknowledged write concern (w=0) it is the id that was sent, the insert itself is not confirmed.

Whether the write was acknowledged

Unitcount

Number of documents inserted into MongoDB