MongoDB Load

MongoDB Load

Certified

Bulk insert documents from internal storage

Reads a Kestra internal storage file of JSON/BSON records and inserts them with MongoDB bulkWrite. Inherits chunking (default 1000). Optionally derives _id from a field and removes that field. Objects whose first key is a MongoDB Extended JSON type wrapper (such as $date, $oid or $numberDecimal) are decoded to that BSON type; a malformed wrapper fails the task with the record and field it was found in. When a write fails, the task fails with the number of the failing record, and its outputs count the records applied before it, which stay in the collection. A retry reads the whole file again: without idKey, the records already written are inserted a second time; with idKey, records with a present idKey fail on retry with a duplicate key error (records where idKey is missing or null receive a generated ObjectId and are inserted again).

yaml
type: io.kestra.plugin.mongodb.Load
yaml
id: mongodb_load
namespace: company.team

inputs:
  - id: file
    type: FILE

tasks:
  - id: load
    type: io.kestra.plugin.mongodb.Load
    connection:
      uri: "mongodb://root:example@localhost:27017/?authSource=admin"
    database: "my_database"
    collection: "my_collection"
    from: "{{ inputs.file }}"
Properties

MongoDB collection

MongoDB connection properties

Definitions
uri*string

Connection string to MongoDB server

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

MongoDB database

Source file

Path in internal storage (kestra://...) containing BSON or JSON documents to stream into MongoDB.

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
Default1000

Bulk chunk size

Number of write models sent per bulkWrite call; defaults to 1000. Must be at least 1.

Field used as _id

If set, the value of this field is stored as _id (converted to an ObjectId if a 24-character hex string or an $oid wrapper, or stored directly as a custom primary key). If the field is missing or null, a new ObjectId is generated.

Defaulttrue

Remove idKey field

When true (default), drops the source field after copying it to _id. Has no effect when idKey is _id.

Default0

Deleted documents

Documents removed by bulk delete models. 0 for unacknowledged writes (w=0), which have no counts to report.

Default0

Inserted documents

Count of documents created by bulk writes. 0 for unacknowledged writes (w=0), which have no counts to report.

Default0

Matched documents

Documents matched by update or replacement models. 0 for unacknowledged writes (w=0), which have no counts to report.

Default0

Modified documents

Documents updated by bulk operations. 0 for unacknowledged writes (w=0), which have no counts to report.

Rows processed

Total records read from the source file. When a write fails, the records applied before it.

Default0

Upserted documents

Documents created by update or replacement models with upsert: true that matched no document. Only Bulk sends these models, so it's always 0 for Load. 0 for unacknowledged writes (w=0), which have no counts to report.

Whether the writes were acknowledged

False with an unacknowledged write concern (w=0): the counts are then 0.

Unitcount

Number of documents processed in the bulk operation; when a write fails, those applied before it

Unitcount

Number of bulk requests sent to MongoDB