Seven MongoDB steps work with your own MongoDB database, one step for each thing you do:

  • MongoDB · Find documents — The documents in a collection that match a filter.
  • MongoDB · Insert a document — Adds one document to a collection.
  • MongoDB · Insert documents — Adds several documents to a collection at once.
  • MongoDB · Update documents — Changes the documents that match a filter.
  • MongoDB · Delete documents — Deletes the documents that match a filter.
  • MongoDB · Aggregate — Runs an aggregation pipeline — group, total, join.
  • MongoDB · Count — How many documents match a filter.

In the step picker, Changes data marks Insert a document, Insert documents and Update documents; Deletes data marks Delete documents; Can change data marks Aggregate, since a pipeline ending in $out or $merge writes.

Who can do this

Workspace Admins and Editors, on every plan.

Before you start

A MongoDB connection in this workspace — see Connect MongoDB. Its user needs read to find, count and aggregate, and readWrite to change documents.

Steps

  1. Select +, then in Apps select MongoDB, or search MongoDB. Choose the step.
  2. Choose the Connection, then the Database and the Collection from their lists.
  3. Fill in the step. Filters, documents and pipelines are written as JSON:
    • Find documents — Filter, for example {"customerEmail": "{{ trigger.email }}"}; empty finds every document. Optional: Fields to return — {"customerEmail": 1, "total": 1} — and Sort — {"createdAt": -1}, highest first.
    • Insert a document — Document, for example {"customerEmail": "{{ trigger.email }}", "total": "{{ trigger.total }}"}. MongoDB gives it an _id unless you do.
    • Insert documents — Documents, a JSON list, or a list from an earlier step — {{ steps.get_rows.rows }}.
    • Update documents — Filter says which documents change. Then either Fields to set, a field and its new value on each row, or Or the update as JSON — {"$inc": {"orders": 1}}. Change: The first match or Every match. Add one when none matches inserts a document when nothing matched (an upsert).
    • Delete documents — Filter, and Delete: The first match or Every match. Deleted documents cannot be brought back.
    • Aggregate — Pipeline, a JSON list of stages, for example [{"$match": {"status": "paid"}}, {"$group": {"_id": "$customerEmail", "total": {"$sum": "$total"}}}].
    • Count — Filter; empty counts every document.
  4. Optional, on Find documents and Aggregate: Most documents — 1,000 unless you change it, up to 10,000.
  5. Select Run this step, then check Output.

Values from earlier steps

  • In quotes, alone, a value keeps its type. "total": "{{ trigger.total }}" stores the number 1250.5, not the text.
  • In quotes with other words, it is text. "note": "Order {{ trigger.id }}".
  • A value can never change the shape of the JSON. Quotes or braces inside a value stay part of the value.
  • A value from an earlier step cannot carry an operator. An object holding a key that starts with $ is refused; write operators in the step itself.
  • An _id from an earlier step is text — wrap it to match an ObjectId: {"_id": {"$oid": "{{ trigger._id }}"}}. Dates likewise: {"$date": "{{ trigger.at }}"}.

Output

Step Field What it is
Find documents, Aggregate count, documents, first How many came back, the documents, and the first of them.
note Only when cut: Only the first 1,000 documents are kept.
Insert a document insertedId The new document's _id, as text.
Insert documents count, insertedIds How many were added, and their _ids.
Update documents matched, modified, upsertedId How many matched, how many changed, and the _id of one added by an upsert.
Delete documents deleted How many were deleted.
Count count How many match.

An ObjectId comes out as text and a date as an ISO time in UTC, so later steps can use them as they are.

Good to know

  • Update documents and Delete documents always need a filter. Changing or deleting every document is not done from a workflow.
  • The update JSON uses operators only — $set, $inc, $push and the rest — so a document is never replaced whole by mistake.
  • 15 seconds to reach the database, 30 seconds for each request. Each step runs once per item.

If something goes wrong

What the run says Why What to do
MongoDB refused: … MongoDB refused the request — a filter it cannot read, a duplicate _id, a right the user lacks. Read the reason; fix the JSON or grant the user the role.
Filter is not JSON MongoDB can read: … The JSON has a mistake — a missing quote or brace. Fix the JSON. The same for Document, Pipeline and the others.
A value from an earlier step holds “$…”, which MongoDB would read as an operator. Write operators in the step itself. A value put into the JSON is an object with a $ key. Use a field of that object, or write the operator in the step.
Filter is empty. Say which documents to change — every one is not taken here. Filter is empty on Update documents. Write the filter. The same for Delete documents.
Say what to change: the fields to set, or the update as JSON. Neither is filled in on Update documents. Fill in one of them.
Give the fields to set, or the update as JSON — not both. Both are filled in. Keep one.
The update JSON must use operators — {"$set": {…}} — so it never replaces a whole document. The update JSON has plain fields. Wrap them in $set.
Choose the database from the list. A value from an earlier step cannot name it. Database holds a {{ }}. Choose it from the list. The same for Collection.
MongoDB did not answer. … The database's network access list does not include Bizomate. See Connect MongoDB.