All nodes/Data/Database

DB Insert

Inserts a document (or an array of documents when many=true) into a NoSQL store collection. Returns inserted_ids.

DB Insert
DocResult

Type in the graph: db_insert

Exec

An error branch can be enabled (expose_error_output) to handle failures on their own path.

Ports can be split into separate execution and data handles.

Try it

Minimal working workflow

Entry
DB Insert
Exit
  • Execute + Data
Press “Copy nodes”, open the editor and hit Ctrl+V on the canvas.

Runs as pasted

When to use it

Insert adds new documents: a ticket from a chat, a log row, a parsed form. It always writes something new — it never checks whether the record is already there. When the record may exist and a repeated run must not pile up duplicates, use db_update with Upsert switched on: it updates the matching document, or creates it once.

How it works

The Doc port carries both the trigger and the document. An object arriving over the edge is the one inserted; when nothing arrives, the document from the Document(s) field is. An array of objects — on the port or in the field — means a bulk insert: the shape of the value is the only thing that decides between one document and many, there is no separate switch.

A document is an object, or a string holding a JSON object. Plain text, a number, or a model’s answer as-is fails the node: build the dictionary upstream — code_javascript returns an object, a template emits a JSON object as a string.

Every document gets an _id unless the document already carries one. The output holds inserted_ids (in the same order) and count.

Common mistakes

  • Expecting protection from duplicates. The same run twice means two documents. Idempotent writes are db_update with Upsert on a unique field.
  • Feeding the model’s answer to the port. The string “Ticket accepted” is not a document. Wrap it in an object, or ask the model for structured output.
  • Taking a custom _id from an unreliable source. It is the row key in the store: a second insert with the same value will not go through. Either leave _id out, or build it so it cannot repeat.
  • Reading an empty array as a failure. It inserts nothing and reports count: 0 — the run succeeded. Check count when an empty list means something to you.
  • Storing files and long texts in a collection. A document has a size ceiling (1 MiB by default) and the workspace has a byte quota. Keep files in file storage and put a reference in the document.

Inputs

PortWirePayloadNotes
DocinputExecute + Dataexecute_data

Run trigger and dynamic payload (overrides static config). The payload must be an object — a value of any other shape fails the node instead of being ignored.

Outputs

PortWirePayloadNotes
ResultoutputExecute + Dataexecute_dataobject

Configuration

FieldTypeDefaultDescription
Collectioncollection_idstring""

Collection ID

Document(s)docobject | array

Static document, or a list of documents for a bulk insert. A value arriving on the `Doc` input port overrides this.

Shared fields

Every node has these three — the platform adds them, not the node author.

  • expose_error_output — When enabled, show an execution output to connect nodes that run if this step fails.
  • split_ports_in — Show separate execution and data input handles instead of one combined port.
  • split_ports_out — Show separate execution and data output handles instead of one combined port.