Update

../../../../_images/update_mongodb.svg

Update one or more documents in the database

Documentation

Update documents from the database matching filter.

When upsert is active and no document matches filter a new document of Update will be created.

The modifications are specified using Update which can be either an update operator expression or an aggregation pipeline. Refer to https://www.mongodb.com/docs/v7.0/reference/operator/update/ for writing operator expressions, and https://www.mongodb.com/docs/v7.0/reference/operator/aggregation-pipeline/ for aggregation pipelines.

The node can be configured to perform an Update One or an Update Many operation. This determines if the update should be performed on only the first or all documents matching filter.

Filter and Update can be specified either as part of the configuration or using opt-in json-ports.

See https://docs.mongodb.com/manual/reference/method/db.collection.updateOne/ and https://docs.mongodb.com/manual/reference/method/db.collection.updateMany/ for more details.

For info on how to input data to MongoDB, see MongoDB data format.

This node can output a write operation, see Output write operation.

Definition

Input ports

mongodb
Type: mongodb
Description: MongoDB
filter
Type: json
Description: Filter
Optional number of ports: 0–1 (default: 0)
update
Type: json
Description: Update
Optional number of ports: 0–1 (default: 0)

Output ports

mongodb
Type: mongodb
Description: MongoDB
Optional number of ports: 0–1 (default: 1)
update_result
Type: json
Description: Update result
Optional number of ports: 0–1 (default: 1)
write_operation
Type: json
Description: Write operation. Output write operation instead of performing the operation directly. The write operation can be used as an element in a bulk write input list
Optional number of ports: 0–1 (default: 0)

Configuration

Filter (filter)

Filter as json.

Operation (operation)

Operation used for updating.

Update (update)

Update as json

Upsert (upsert)

If True, perform an insert if no documents match the filter.

Examples

Example flows demonstrating this node:

Implementation

class node_mongodb.MongoDBUpdate[source]