All nodes/Data/Database

DB Update

Updates documents matching the filter with a MongoDB-style update expression ($set, $inc, $push, ...). Supports upsert and multi.

DB Update▶
Filter and updateOutcome

Type in the graph: db_update

Exec

An error output can be enabled to handle failures on their own path.

Ports can be split into separate execution and data handles.

Try it

Minimal working scenario

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

Runs as pasted

When to use it

Update changes existing documents: move a ticket to another status, bump a counter, append an item to an array. With Create if missing on it becomes “create or update” — the only way to write a document by key so that a repeated run leaves no duplicate (db_insert has no such check). The Update many flag switches the node from one document to every match.

How it works

Two expressions are needed: Filter picks the documents, Update says what to do with them ($set, $inc, $push, $unset, $addToSet and other operators). The Filter and update port accepts an envelope {"filter": …, "update": …}, in which case both halves arrive over the edge; any other object is treated as the filter and the update expression stays as configured.

The output has three fields: matched (how many documents the filter picked), modified (how many actually changed) and upserted_id (the id of the document created when an upsert fired).

Common mistakes

  • An expression with no operator. {"status": "paid"} without $set is not a field edit but a whole-document replacement: the other fields disappear and only _id survives. Write {"$set": {"status": "paid"}}.
  • Judging success by modified. Zero there does not only mean “nothing matched”: a document that already holds the value is not rewritten, and an upsert also leaves the counter at zero — the new document shows up in upserted_id. Read all three fields.
  • Forgetting to switch on “Update many”. With the flag off exactly one of the matching documents changes, and which one is undefined.
  • Expecting upsert to carry the whole filter into the new document. Only plain top-level equalities are seeded; conditions such as {"$gt": …} and dotted paths are not — set those fields explicitly in $set.
  • Templates in the fields. Filter and Update are JSON editors; {{ … }} is not expanded there. Build the dynamic part with code_javascript or a template and feed it to the port.
  • $inc on a non-numeric field. If the field holds a string the node fails; coerce the type when you write it.

Inputs

PortWirePayloadNotes
Filter and updateinputExecute + Dataexecute_data—

A value arriving here REPLACES the configured filter — or, with a {"filter": …, "update": …} envelope, both of them — it does not merge with it, and it must be an object (any other shape fails the node instead of being ignored). To trigger the node while keeping what you configured, wire the port's exec leg (Run) instead, and put {{ }} templates in the field itself.

Outputs

PortWirePayloadNotes
OutcomeoutputExecute + Dataexecute_dataobject

Configuration

FieldTypeDefaultDescription
Collectioncollection_idstring""

Collection ID

Filterfilterobject—

MongoDB-style filter expression choosing which records to update.

overridden by port: input

Update manymultibooleanfalse

Update every matching record. Off = only the first match.

Updateupdateobject—

MongoDB-style update expression ($set, $inc, $push, ...). A bare object on the port is taken as the filter and leaves this field alone; only an envelope {"filter": …, "update": …} replaces it.

Create if missingupsertbooleanfalse

When nothing matches the filter, insert a new record instead of doing nothing.

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.