MongoDB Ex icon

MongoDB Ex

MongoDB Extended - Advanced MongoDB operations, including support for filters, bulk operations, full update JSON support and more.

Document → Find And Update

AI-generated

Summary

Update matching documents in a MongoDB collection, optionally upserting and returning the modified document.

Inputs

  • collection (required) — MongoDB Collection
  • updateFilter (required) — MongoDB filter object that determines which documents should be updated. You can construct complex filters using MongoDB query operators.
  • update — Provide a MongoDB update definition. You can configure a full update object (e.g. {$set, $unset, $inc, ...}) or an update pipeline (array of stages).
  • upsert — Whether to perform an insert if no documents match the update key
  • options — Various query options such as timeout, maxTimeMS, hint, arrayFilters, and returnDocument.

Output shape

array of updated document objects

Each element corresponds to one input record and contains the updated document; may include error fields on failure.

Examples

Example 1: Update a document by its ID with $set and $inc, returning the new version.

collection: "users", updateFilter: {"_id":"{{$json.id}}"}, update: {"$set":{"name":"John"},"$inc":{"counter":1}}, upsert: false, options: {}

Example 2: Perform an upsert to create the document if it does not exist.

collection: "logs", updateFilter: {"timestamp":"{{$json.timestamp}}"}, update: {"$set":{"count":1}}, upsert: true, options: {"returnDocument":"after"}

Example 3: Use arrayFilters to increment only pending items in an array.

collection: "orders", updateFilter: {"customer":"{{$json.customer}}"}, update: {"$inc":{"items.$[elem].quantity":1}}, upsert: false, options: {"arrayFilters":[{"elem.status":"pending"}],"returnDocument":"after"}

Discussion