I’m running into the following error when using a MongoDB node as agent memory in my workflow:
Error: Cannot read properties of undefined (reading 'client')
NodeOperationError: Error in sub-node MongoDB Chat Memory at ExecuteContext.getInputConnectionData (C:\Users\FritzerJos\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-core\src\execution-engine\node-execution-context\utils\get-input-connection-data.ts:352:11) at processTicksAndRejections (node:internal/process/task_queues:105:5) at ExecuteContext.getInputConnectionData (C:\Users\FritzerJos\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-core\src\execution-engine\node-execution-context\execute-context.ts:180:10) at getOptionalMemory (C:\Users\FritzerJos\AppData\Roaming\npm\node_modules\n8n\node_modules@n8n\n8n-nodes-langchain\nodes\agents\Agent\agents\ToolsAgent\common.ts:314:10) at ExecuteContext.toolsAgentExecute (C:\Users\FritzerJos\AppData\Roaming\npm\node_modules\n8n\node_modules@n8n\n8n-nodes-langchain\nodes\agents\Agent\agents\ToolsAgent\V2\execute.ts:194:17) at ExecuteContext.execute (C:\Users\FritzerJos\AppData\Roaming\npm\node_modules\n8n\node_modules@n8n\n8n-nodes-langchain\nodes\agents\Agent\V2\AgentV2.node.ts:131:10) at WorkflowExecute.executeNode (C:\Users\FritzerJos\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-core\src\execution-engine\workflow-execute.ts:1093:8) at WorkflowExecute.runNode (C:\Users\FritzerJos\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-core\src\execution-engine\workflow-execute.ts:1274:11) at C:\Users\FritzerJos\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-core\src\execution-engine\workflow-execute.ts:1699:27 at C:\Users\FritzerJos\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-core\src\execution-engine\workflow-execute.ts:2315:11
I’m on n8n version 1.116.2.
What I’ve checked so far:
The MongoDB connection test in the node’s credentials setup passes successfully.
The connection details (URI, authentication, etc.) are correct and match my MongoDB instance.
Additional context:
The error occurs specifically when the workflow tries to use the MongoDB node for agent memory operations.
No issues with other nodes or database connections.
Has anyone encountered this issue or have suggestions on how to resolve it? Any insights would be greatly appreciated!
I had an issue of Error: Cannot read properties of undefined (reading ‘client’) in n8n Version 1.118.1, and I solved it by adding this code to: C:\Users\AppData\Roaming\npm\node_modules\n8n\node_modules@n8n\n8n-nodes-langchain\dist\nodes\vector_store\VectorStoreMongoDBAtlas\VectorStoreMongoDBAtlas.node.js
if (collection) {
if (collection.db === void 0) {
collection.db = db;
}
if (collection.db?.client && typeof collection.db.client.appendMetadata !== "function") {
collection.db.client.appendMetadata = () => {
};
}
const collection = db.collection(collectionName);
await ExtendedMongoDBAtlasVectorSearch.fromDocuments(documents, embeddings, {
collection,
indexName: mongoVectorIndexName,
// Default index name
textKey: metadataFieldName,
// Field containing raw text
embeddingKey: embeddingFieldName
// Field containing embeddings
});
replace with:
const collection = db.collection(collectionName);
if (collection) {
if (collection.db === void 0) {
collection.db = db;
}
if (collection.db && collection.db.client && typeof collection.db.client.appendMetadata !== "function") {
collection.db.client.appendMetadata = () => {};
}
}
await ExtendedMongoDBAtlasVectorSearch.fromDocuments(documents, embeddings, {
collection,
indexName: mongoVectorIndexName,
// Default index name
textKey: metadataFieldName,
// Field containing raw text
embeddingKey: embeddingFieldName
// Field containing embeddings
});