Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
MongoDB Branding Shape
Click here >
Docs Menu

Integrate MongoDB with n8n

You can integrate MongoDB with n8n to build automations and agentic workflows using their no-code visual interface. This page provides an overview of the integration and describes the different types of nodes that you can use in your workflows.

To install n8n, refer to the n8n documentation or run the following command using npm to quickly get started:

npx n8n

To learn how to build a basic AI agent using n8n and MongoDB, see Build an AI Agent with MongoDB and n8n.

Important

All MongoDB n8n nodes require you to configure your MongoDB credentials in n8n. To learn more, see MongoDB Credentials.

The MongoDB node allows you to automate work in MongoDB and integrate MongoDB with other nodes in your n8n workflows.

Use the MongoDB node in any of your custom n8n workflows.

The MongoDB node supports the following operations:

Category
Operation
Description

Document Operations

Aggregate Documents

Perform aggregation operations to process and transform data using MongoDB aggregation pipelines.

Find Documents

Query and retrieve documents from your MongoDB collections with flexible filtering options.

Insert Documents

Add new documents to your MongoDB collections.

Update Documents

Modify existing documents in your collections.

Delete Documents

Remove documents from your collections.

Find and Replace Documents

Search for documents and replace them with new content.

Find and Update Documents

Search for documents and update specific fields.

Search Index Operations

Create Search Indexes

Create new search and vector search indexes on your collections.

List Search Indexes

Retrieve information about existing search indexes.

Update Search Indexes

Modify existing search index configurations.

Drop Search Indexes

Remove search indexes that are no longer needed.

Tip

The MongoDB Atlas Vector Store node enables you to use MongoDB Vector Search in your agentic workflows.

Note

Before you can start using this node, configure the MongoDB Vector Search Index.

Use the MongoDB Vector Store node in the following workflow patterns:

Connect directly to an AI agent as a tool to perform agentic RAG.

AI Agent (tools connector) → MongoDB Vector Store

For a tutorial, see Build an AI Agent with MongoDB and n8n.

To learn more about AI agents in n8n, see AI agent node.

Use the MongoDB Atlas Vector Store as a regular node to insert or retrieve documents in your custom workflows:

Trigger → MongoDB Vector Store (Insert/Get) → Next Node

To learn more, see Nodes.

Use the node as a retriever in a question-answering chain:

Question and Answer Chain → Vector Store Retriever → MongoDB Vector Store

To learn more about Q&A in n8n, see Question and Answer Chain node.

Use the node as a question-answering tool for an AI agent:

AI Agent → Vector Store Question Answer Tool → MongoDB Vector Store

To learn more about the question-answering tool in n8n, see Vector Store Question Answer Tool node.

The MongoDB Vector Store node supports the following operation modes. The retrieve document mode is only available in certain workflow patterns.

Operation Mode
Description

Get Many

Retrieve multiple documents using similarity search based on a prompt. Returns documents with similarity scores.

Insert Documents

Add new documents with vector embeddings to your collection.

Retrieve Documents (As Vector Store for Chain/Tool)

Only available when you use the node as a retriever or a tool. Must be connected to a retriever node or root node.

Retrieve Documents (As Tool for AI Agent)

Only available when you use the node as a tool for an AI agent. The agent uses this vector store when the name and description are relevant to the prompt.

Configure the MongoDB Vector Store node with the following parameters.

Category
Setting
Operation Mode
Description

Common Parameters

MongoDB Collection

All

Name of the MongoDB collection to use.

Vector Index Name

All

Name of the Vector Search index in your MongoDB collection.

Embedding Field

All

Field name in your documents that contains the vector embeddings.

Metadata Field

All

Field name in your documents that contains the text metadata.

Mode-Specific Parameters

Name

Retrieve Documents (As Tool for AI Agent)

Name of the vector store tool for the AI agent.

Description

Retrieve Documents (As Tool for AI Agent)

Explanation for the LLM about what this tool does.

Limit

Retrieve Documents (As Tool for AI Agent)

Number of results to retrieve from the vector store.

Additional Options

Metadata Filter

Get Many, Retrieve Documents (As Tool for AI Agent), Retrieve Documents (As Vector Store for Chain/Tool)

Filter results based on metadata criteria.

Rerank Results

Get Many, Retrieve Documents (As Tool for AI Agent), Retrieve Documents (As Vector Store for Chain/Tool)

Enable result reranking (requires connecting a reranker node).

The MongoDB Chat Memory node allows you to use MongoDB as a memory store for storing chat history in your AI workflows. This enables persistent conversation context across workflow executions.

You must use the MongoDB Chat Memory node as a sub-node by adding it to the Memory section of an AI agent node. For a tutorial, see Build an AI Agent with MongoDB and n8n.

Note

If you add multiple MongoDB Chat Memory nodes to your workflow, all nodes access the same memory instance by default. For separate memory instances, use different session IDs in each memory node.

Configure the MongoDB Chat Memory node with these parameters.

Parameter
Description

Session ID

Method for determining how the session key is identified. You can define the session key through a connected trigger, or you can define the key manually.

Session Key

Unique identifier for the chat session.

Collection Name

Name of the collection to store chat history. MongoDB creates the collection if it doesn't exist. Defaults to n8n_chat_histories.

Database Name

Name of the database to store chat history. If not provided, n8n uses the database from credentials.

Context Window Length

Number of previous interactions to consider for context.

To learn more about n8n, use the following resources: