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.
| Field | What 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 Filter | With 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
| Field | What it does |
|---|---|
| Upsert | Creates a new document if none meets the filter. Off by default. |
| Multiple Documents | On (default), changes apply to every document that meets the filter; off, only to the first one. |
| Limit | The maximum number of documents Find returns. Default: 100. |
| Skip | How many results to skip, to read page by page. Default: 0. |
| Sort | The order of the results: 1 ascending and -1 descending, for example {"date": -1} for the newest first. |
| Return ID | Includes 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.
- Add Document with the MongoDB Connection credential, the
shopdatabase and theorderscollection. - Choose
Update. - In Filter type
{"number": "A-1043"}and in Update Data{"$set": {"status": "shipped"}}.
Good practices
- Test the filter with
Findbefore using it withUpdateorDelete, and turn off Multiple Documents if you only want to touch one.
Related components
- Search Index: manages a collection’s search indexes.
- MongoDB Vector Store: search by meaning in MongoDB Atlas.