Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ export class MemoryMongoDbChat implements INodeType {
);
}

let client: MongoClient|null=null;
try {
const client = new MongoClient(connectionString);
client=new MongoClient(connectionString);
await client.connect();

const db = client.db(dbName);
Expand All @@ -148,6 +149,9 @@ export class MemoryMongoDbChat implements INodeType {
outputKey: 'output',
k: this.getNodeParameter('contextWindowLength', itemIndex, 5) as number,
});

// wait for response before return
await memory.chatHistory.getMessages();

async function closeFunction() {
await client.close();
Expand All @@ -158,6 +162,10 @@ export class MemoryMongoDbChat implements INodeType {
response: logWrapper(memory, this),
};
} catch (error) {
try { // force to close client
await client.close();
} catch (error) {
}
throw new NodeOperationError(this.getNode(), `MongoDB connection error: ${error.message}`);
}
}
Expand Down