How to Connect n8n to MongoDB: Store and Query Data Without Code (2025)

MongoDB is the default home for flexible, document-shaped data — logs, user records, product catalogs, event streams. n8n turns that database into an active participant in your automations: every workflow can read from it, write to it, and make decisions based on what's inside. No ORM, no backend service, no boilerplate.

What you'll need

  • An n8n instance
  • A MongoDB database (Atlas or self-hosted)
  • A connection string with a user that has the right read/write roles

Step 1 — Create the credential

n8n ships a native MongoDB node. Add a credential with your connection string (for Atlas, the mongodb+srv:// URI). If you're on Atlas, remember to allow your n8n server's IP in the network access list — the most common reason a first connection silently times out.

Step 2 — Insert documents

Use the Insert operation to write data from any trigger — a form submission, a webhook, an API response. Map your fields to a document and n8n handles the write. Because Mongo is schemaless, you can evolve the shape over time without migrations.

Step 3 — Find and filter

The Find operation takes a standard MongoDB query object. Filter by any field, sort, limit, and project only the fields you need. This is how your workflows look up existing records — check if a user exists, pull recent orders, fetch a config document.

Step 4 — Update and upsert

Use Update with an upsert option to create-or-modify in a single step — perfect for keeping a record current without checking existence first. This de-dupes your data automatically.

⚡ Skip the build — get the ready-made template

Let anyone on your team query the database in plain English — this AI workflow turns questions into safe queries and returns clean answers.

Get the "Text-to-SQL: Ask Your Database in Plain English" template on Gumroad →

Step 5 — Aggregate for reporting

MongoDB's aggregation pipeline is a powerhouse, and n8n exposes it. Group, count, sum, and join across collections to produce summaries — daily revenue, active users, top products — then push the result into a Slack digest or a dashboard. Your reporting runs on a schedule with zero manual queries.

Step 6 — Let AI query it in plain English

Here's the upgrade that changes who can use your data. Wrap the MongoDB node with an AI step that translates a natural-language question — "how many orders over $500 came from Brazil last month?" — into a safe query, runs it, and returns a readable answer. Non-technical teammates get answers from the database without knowing a line of query syntax, and you never write another ad-hoc report by hand.

Practical patterns

  • Event store: webhooks write events to Mongo; scheduled workflows aggregate them into metrics.
  • State for automations: use a collection to remember what your workflows have already processed (de-duplication done right).
  • Enrichment cache: store API lookups in Mongo so you don't pay to re-fetch the same data.

Tips

  • Index the fields you filter on — an un-indexed Find on a large collection will crawl.
  • Use a least-privilege database user; if a workflow only reads, don't give it write access.
  • Guard AI-generated queries with validation so a bad prompt can't produce a destructive operation.

Ready to automate?

You can wire this together node by node — or install a battle-tested version in minutes. The Text-to-SQL: Ask Your Database in Plain English template comes fully built, documented, and ready to import into your n8n instance.

Get this template on Gumroad →

One-time purchase. Lifetime updates. Works on n8n Cloud and self-hosted.