- Home
- Resources
- Integrations
- MongoDB Chat Memory
n8n MongoDB Chat Memory nodeConfigure MongoDB Chat Memory in n8n.
A chatbot that forgets everything between two messages is not a chatbot. The n8n MongoDB Chat Memory node is a sub-node, a helper node with no main input that plugs into the Memory port of a root node and writes each exchange into a MongoDB collection. Four parameters, one version.
Verified Trustpilot reviews · AI, automation & growth agency
What does the n8n MongoDB Chat Memory node actually store?
It stores the chat history of a conversation in a MongoDB collection, so the model gets the previous turns back on the next message. In an AI context, memory is what lets a tool keep message context across interactions instead of receiving the whole conversation again in every prompt. The node itself never runs alone: it waits on the Memory port of a root node and answers when that node asks for history.
The first scenario is the one most people land here for: a support assistant that answers on a chat widget. The root node handles the question, and Collection Name points at the MongoDB collection where every question and answer pair ends up. The collection does not have to exist beforehand, n8n creates it on the first write. Plug the node into an AI Agent and the follow-up question keeps its subject.
Second scenario, a multi-tenant assistant. One MongoDB database, one collection, and one conversation per customer, kept apart by the session key. That key is the whole point of Session ID: two visitors who share a session key share a conversation, which is exactly what you do not want. The same separation applies when an agent is exposed as a tool through AI Agent Tool.
Third scenario, long conversations that get expensive. Context Window Length caps how many past interactions travel with each call, so a thread that has been running all afternoon does not replay itself to the model every time. The model provider, whether that is OpenAI, Google Gemini or another one, bills its own API calls under its own terms, and n8n adds nothing on top of that.
When would you skip this node? When the conversation does not need to survive the workflow run. Memory is available to AI agent nodes, not to AI chains, so a chain that classifies one message at a time has nothing to gain here. And if the workflow already runs on a MongoDB instance you would rather not open to chat logs, the node is not the right place to force it.
Two limits worth knowing before you build. Add a second MongoDB Chat Memory node to the same workflow and both point at the same memory instance by default, so a destructive action on one is a destructive action on the other. Set different session IDs when you want genuinely separate instances. Second limit, the page describes version 1 of the node, the highest one in the catalog, and an older workflow may show fewer options. More context on the platform itself sits in the n8n review.
What do you connect before the node works?
- 01
Create the MongoDB credential
Open the Credentials menu in n8n and create a MongoDB credential, the stored set of connection details n8n reuses instead of asking you again in every workflow. The official n8n documentation covers the authentication details for this node. Once saved, the same credential serves every workflow on the instance, on n8n Cloud as well as on a self-hosted install.
- 02
Select it on the node
Drop the node on the canvas and pick that credential in its credential selector. There is no Authentication dropdown to choose from here: the node has one credential type and nothing else to arbitrate. The node ships inside the n8n AI package, so nothing needs installing first, on n8n Cloud or on a self-hosted instance.
- 03
Point it at a database and a collection
Leave Database Name empty and the node uses the database carried by the credential itself. Fill it in when the chat history belongs somewhere else than the default. Then set Collection Name, and stop worrying about creating it by hand: if the collection does not exist, the node creates it.
Where does the node plug in?
n8n AI nodes work as a root node that receives the workflow items, with sub-nodes hanging off its ports, one type of sub-node per port. This one is a sub-node with a single output, so the only question is which root node it serves.
Output (what it plugs into)
- Memory
ai_memory
01Memory
The Memory port is where a root node asks for past messages before calling the model, then writes the new exchange. This node occupies that port and nothing else.
Key parameters
- Optional: a root node runs without memory, it just answers each message as if it were the first.
- AI Agent: the usual host, the agent that answers and needs the earlier turns.
- AI Agent Tool: same idea when the agent is itself called as a tool by another one.
- Chat Memory Manager: reads or rewrites the stored history on purpose.
- Chat Trigger: the chat entry point holds the thread from the first message.
How do you set the four parameters?
The MongoDB Chat Memory node has 4 parameters. For each one: the node as you configure it in n8n, what the parameter changes, and our field notes.
Parameters index
Session ID
sessionIdTypeWhat you see in n8n
Notes & use cases
This decides how the node names the conversation it reads and writes. Get it wrong and two users share one thread.
Key parameters
- Connected Chat Trigger Node (
fromInput): looks for an input field calledsessionIdcoming from a directly connected Chat Trigger. - Define below (
customKey): use an expression to reference data in previous nodes, or enter static text. - Session Key From Previous Node: the field that appears with the second choice, typically
{{ $json.sessionId }}or a customer identifier.
Collection Name
collectionNameWhat you see in n8n
Notes & use cases
Names the MongoDB collection where the chat history is stored. If the collection does not exist, it will be created, so there is no setup step in MongoDB before the first run.
Key parameters
- Collection Name: the collection name to store the chat history in, a plain string such as
chat_history, or an expression when one workflow serves several products.
Database Name
databaseNameWhat you see in n8n
Notes & use cases
Chooses which MongoDB database holds that collection. Left empty, the database from credentials will be used, which is what you want as long as one credential serves one environment.
Key parameters
- Database Name: the database name to store the chat history in, filled only when the history belongs outside the credential default.
Context Window Length
contextWindowLengthWhat you see in n8n
Notes & use cases
Sets how many past interactions the model receives as context. It is the dial between an assistant that remembers the whole thread and one that only remembers the last few turns.
Key parameters
- Context Window Length: a number of previous interactions, raised when answers need the early part of the conversation, lowered when each call carries too much history.
Need help automating MongoDB Chat Memory with n8n?
A person reads every message.
MongoDB Chat Memory and n8n, the questions that come next
01Is the MongoDB Chat Memory node included in n8n?
02What credentials does the node need?
03What are the limits of the n8n MongoDB Chat Memory node?
04What do you need to plug in for the memory to work?
05n8n or Make for a chatbot with persistent memory?
Get our weekly integration tips.
No spam. Unsubscribe anytime.


