Error in establishing connection to mongodb vector index

Subject: Unable to Connect to MongoDB Vector Index Collection from n8n

Description:

I am experiencing an issue with connecting to a MongoDB vector index collection from n8n. The error message displayed is:

Problem in node ‘MongoDB Atlas Vector Store1‘
Error: Error: Server selection timed out after 30000 ms

Workflow Details:

I have two workflows set up:

  1. Workflow 1: Retrieves files from Google Docs, creates embeddings, and uploads the document to a MongoDB vector store.
  2. Workflow 2: Utilizes an AI agent to chat and retrieve information from the MongoDB vector index if needed. This workflow also connects to a separate collection in the same cluster to store session history, which works without issues.

Despite being able to connect and store data in the session history collection, I am unable to connect to the vector index collection. Below is the JSON configuration of my workflow:

my workflow json:
{
“nodes”: [
{
“parameters”: {
“public”: true,
“initialMessages”: “Hi there! :waving_hand:\nMy name is Jackky. How can I assist you today?”,
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.chatTrigger”,
“typeVersion”: 1.1,
“position”: [
-1040,
-180
],
“id”: “ce2df614-d16d-43e7-ae3d-c91dda271791”,
“name”: “When chat message received”,
“webhookId”: “d59b0739-6e41-4345-9359-fa39a46a739b”
},
{
“parameters”: {
“options”: {
“systemMessage”: “You are a professional, helpful assistant. Your answers are concise, helpful - brief but comprehensive. If you provide code snippets, leave out comments. You are also helping a user find information in a knowledge base.”
}
},
“type”: “@n8n/n8n-nodes-langchain.agent”,
“typeVersion”: 2,
“position”: [
-820,
-180
],
“id”: “c39397e4-427c-40a3-99f2-ec5dfa8fdc00”,
“name”: “AI Agent”
},
{
“parameters”: {
“collectionName”: “messages”,
“databaseName”: “n8n-test-db”
},
“type”: “@n8n/n8n-nodes-langchain.memoryMongoDbChat”,
“typeVersion”: 1,
“position”: [
-680,
60
],
“id”: “54c73136-6f56-48d0-98b7-0b0207a79f6e”,
“name”: “MongoDB Chat Memory”,
“credentials”: {
“mongoDb”: {
“id”: “vFuieOYcc2cfxkJp”,
“name”: “MongoDB account 5”
}
}
},
{
“parameters”: {
“operation”: “get”,
“documentURL”: “https://docs.google.com/document/d/1UOdwIBShT3052b3ON8PGPOQqOn6o5gT9tz6i0cMORwM/edit?tab=t.0
},
“type”: “n8n-nodes-base.googleDocs”,
“typeVersion”: 2,
“position”: [
-780,
-820
],
“id”: “c61d2c09-dedb-4cf6-a95c-a876fc1e2625”,
“name”: “Google Docs”,
“credentials”: {
“googleDocsOAuth2Api”: {
“id”: “dEWIpf5tmoA3gi8N”,
“name”: “Google Docs account”
}
}
},
{
“parameters”: {
“mode”: “insert”,
“mongoCollection”: {
“__rl”: true,
“value”: “trimble-agentic-scratch”,
“mode”: “list”,
“cachedResultName”: “trimble-agentic-scratch”
},
“vectorIndexName”: “vector_index_test”,
“options”: {
“namespace”: “”
}
},
“type”: “@n8n/n8n-nodes-langchain.vectorStoreMongoDBAtlas”,
“typeVersion”: 1.2,
“position”: [
-100,
-820
],
“id”: “965c29f7-490e-41f5-b05e-b863bd479577”,
“name”: “MongoDB Atlas Vector Store1”,
“credentials”: {
“mongoDb”: {
“id”: “vFuieOYcc2cfxkJp”,
“name”: “MongoDB account 5”
}
}
},
{
“parameters”: {
“jsonMode”: “expressionData”,
“jsonData”: “={{ $json.content }}”,
“options”: {
“metadata”: {
“metadataValues”: [
{
“name”: “doc_id”,
“value”: “={{ $json.documentId }}”
},
{
“name”: “tags”,
“value”: “={{ $json.Tags }}”
}
]
}
}
},
“type”: “@n8n/n8n-nodes-langchain.documentDefaultDataLoader”,
“typeVersion”: 1,
“position”: [
200,
-580
],
“id”: “fae938d2-f4a9-4a25-9993-72d9d8abd240”,
“name”: “Default Data Loader”
},
{
“parameters”: {
“chunkOverlap”: 200,
“options”: {
“splitCode”: “markdown”
}
},
“type”: “@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter”,
“typeVersion”: 1,
“position”: [
360,
-420
],
“id”: “b4064648-5e0e-4591-b22c-61d2a19e2a99”,
“name”: “Recursive Character Text Splitter”
},
{
“parameters”: {
“mode”: “retrieve-as-tool”,
“toolName”: “knowledgeBase”,
“toolDescription”: “retrieve documents”,
“mongoCollection”: {
“__rl”: true,
“value”: “trimble-agentic-scratch”,
“mode”: “list”,
“cachedResultName”: “trimble-agentic-scratch”
},
“vectorIndexName”: “vector_index_test”,
“topK”: 10,
“options”: {
“metadata”: {
“metadataValues”: [
{
“name”: “tags”,
“value”: "={{ $json.chatInput.split(" ").first()}} "
}
]
}
}
},
“type”: “@n8n/n8n-nodes-langchain.vectorStoreMongoDBAtlas”,
“typeVersion”: 1.2,
“position”: [
-480,
60
],
“id”: “52984f8f-7d50-4d14-aa10-c3afd4067778”,
“name”: “MongoDB Atlas Vector Store”,
“credentials”: {
“mongoDb”: {
“id”: “vFuieOYcc2cfxkJp”,
“name”: “MongoDB account 5”
}
}
},
{
“parameters”: {
“model”: “text-embedding-ada-002”,
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.embeddingsAzureOpenAi”,
“typeVersion”: 1,
“position”: [
-160,
-600
],
“id”: “f37ce584-9b32-4925-b385-2ba6183278d0”,
“name”: “Embeddings Azure OpenAI”,
“credentials”: {
“azureOpenAiApi”: {
“id”: “eq5TpP5OqmDlwF0E”,
“name”: “Azure Open AI account 6”
}
}
},
{
“parameters”: {
“model”: “text-embedding-ada-002”,
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.embeddingsAzureOpenAi”,
“typeVersion”: 1,
“position”: [
-340,
220
],
“id”: “a362b50d-56ea-4cb8-942f-61496f4cf16b”,
“name”: “Embeddings Azure OpenAI1”,
“credentials”: {
“azureOpenAiApi”: {
“id”: “eq5TpP5OqmDlwF0E”,
“name”: “Azure Open AI account 6”
}
}
},
{
“parameters”: {
“assignments”: {
“assignments”: [
{
“id”: “e9a020d7-e377-4af3-ba75-38f0efc873d9”,
“name”: “Tags”,
“value”: “["china"]”,
“type”: “array”
}
]
},
“includeOtherFields”: true,
“options”: {}
},
“type”: “n8n-nodes-base.set”,
“typeVersion”: 3.4,
“position”: [
-460,
-820
],
“id”: “25c6070a-c792-413f-899b-a4ca6b5ca6d9”,
“name”: “Edit Fields”
},
{
“parameters”: {
“model”: “gpt-4o”,
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.lmChatAzureOpenAi”,
“typeVersion”: 1,
“position”: [
-920,
60
],
“id”: “4a418628-7ec4-4520-a499-63357330d81e”,
“name”: “Azure OpenAI Chat Model”,
“credentials”: {
“azureOpenAiApi”: {
“id”: “pxWwLrrMBfTZd9ff”,
“name”: “Azure Open AI account 8”
}
}
},
{
“parameters”: {},
“type”: “n8n-nodes-base.manualTrigger”,
“typeVersion”: 1,
“position”: [
-1280,
-780
],
“id”: “d4f610c6-1181-41ed-a88c-f683e476d7aa”,
“name”: “When clicking ‘Execute workflow’”
}
],
“connections”: {
“When chat message received”: {
“main”: [
[
{
“node”: “AI Agent”,
“type”: “main”,
“index”: 0
}
]
]
},
“AI Agent”: {
“main”: [

]
},
“MongoDB Chat Memory”: {
“ai_memory”: [
[
{
“node”: “AI Agent”,
“type”: “ai_memory”,
“index”: 0
}
]
]
},
“Google Docs”: {
“main”: [
[
{
“node”: “Edit Fields”,
“type”: “main”,
“index”: 0
}
]
]
},
“Default Data Loader”: {
“ai_document”: [
[
{
“node”: “MongoDB Atlas Vector Store1”,
“type”: “ai_document”,
“index”: 0
}
]
]
},
“Recursive Character Text Splitter”: {
“ai_textSplitter”: [
[
{
“node”: “Default Data Loader”,
“type”: “ai_textSplitter”,
“index”: 0
}
]
]
},
“MongoDB Atlas Vector Store”: {
“ai_tool”: [
[
{
“node”: “AI Agent”,
“type”: “ai_tool”,
“index”: 0
}
]
]
},
“Embeddings Azure OpenAI”: {
“ai_embedding”: [
[
{
“node”: “MongoDB Atlas Vector Store1”,
“type”: “ai_embedding”,
“index”: 0
}
]
]
},
“Embeddings Azure OpenAI1”: {
“ai_embedding”: [
[
{
“node”: “MongoDB Atlas Vector Store”,
“type”: “ai_embedding”,
“index”: 0
}
]
]
},
“Edit Fields”: {
“main”: [
[
{
“node”: “MongoDB Atlas Vector Store1”,
“type”: “main”,
“index”: 0
}
]
]
},
“Azure OpenAI Chat Model”: {
“ai_languageModel”: [
[
{
“node”: “AI Agent”,
“type”: “ai_languageModel”,
“index”: 0
}
]
]
},
“When clicking ‘Execute workflow’”: {
“main”: [
[
{
“node”: “Google Docs”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “7695a91126d09b133fd392aa1cf02a82a0edb2398e11546df24da809f5b623b9”
}
}

Hi @Gokula_Krishnan_K,

Some things to check out and help us debug:

  • Are the vector store and the chat memory using the same credential?
  • Are the permissions set up correctly?
  • Is the issue with the vector store with the reading, or the inserting data?