Skip to content

Document

Document is the MongoDB component for working with the documents of a collection: finding them, adding new ones, changing, replacing, deleting or counting them.

When to use it

  • Saving in MongoDB the data that arrives through a form or an API.
  • Giving an agent access to look up orders or customers stored in MongoDB.
  • Marking as processed the documents a flow has already handled.
  • Counting how many documents meet a condition for a report.

Configuration

The Operation field decides what the component does: Find (default), Insert, Update, Delete, Count or Replace. Conditions and data are written in MongoDB format, for example {"status": "active"}.

You need a MongoDB Connection credential with your MongoDB cluster details. See Credentials.

FieldWhat it does
Credential (required)The MongoDB Connection credential.
Database Name (required)The database that holds the collection.
Collection Name (required)The collection to work with.
Operation (required)What the component does.
Filter (required)Which documents are changed, replaced or deleted. For example, {"status": "active", "age": {"$gt": 18}}. Use {} for all with Update and Replace; Delete refuses {} so a collection is never emptied by mistake.
Query FilterWith Find and Count, which documents are found or counted. Empty or {}, all.
Document (required)With Insert and Replace, the document added or replacing the existing one, for example {"name": "Ana", "email": "ana@example.com"}. It can come from another component; with Insert, a list of data adds one document per item.
Update Data (required)With Update, what changes, with MongoDB operators: {"$set": {"status": "active"}} changes a value and {"$inc": {"visits": 1}} adds one.

Advanced options

FieldWhat it does
UpsertCreates a new document if none meets the filter. Off by default.
Multiple DocumentsOn (default), changes apply to every document that meets the filter; off, only to the first one.
LimitThe maximum number of documents Find returns. Default: 100.
SkipHow many results to skip, to read page by page. Default: 0.
SortThe order of the results: 1 ascending and -1 descending, for example {"date": -1} for the newest first.
Return IDIncludes each document’s MongoDB ID. On by default.

Output

The Data output holds the documents found, the count or the result of the change.

In tool mode, an agent can use the component by itself. See Tool Mode.

Example

An online shop wants to mark as shipped the orders that already have a tracking number.

  1. Add Document with the MongoDB Connection credential, the shop database and the orders collection.
  2. Choose Update.
  3. In Filter type {"number": "A-1043"} and in Update Data {"$set": {"status": "shipped"}}.

Good practices

  • Test the filter with Find before using it with Update or Delete, and turn off Multiple Documents if you only want to touch one.