diff --git a/packages/components/nodes/vectorstores/MongoDBAtlas/MongoDBAtlas.ts b/packages/components/nodes/vectorstores/MongoDBAtlas/MongoDBAtlas.ts index 04b881b9b..12bbb1a26 100644 --- a/packages/components/nodes/vectorstores/MongoDBAtlas/MongoDBAtlas.ts +++ b/packages/components/nodes/vectorstores/MongoDBAtlas/MongoDBAtlas.ts @@ -4,7 +4,7 @@ import { MongoDBAtlasVectorSearch } from '@langchain/mongodb' import { Embeddings } from '@langchain/core/embeddings' import { Document } from '@langchain/core/documents' import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams, IndexingResult } from '../../../src/Interface' -import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' +import { getBaseClasses, getCredentialData, getCredentialParam, getVersion } from '../../../src/utils' import { addMMRInputParams, resolveVectorStoreOrRetriever } from '../VectorStoreUtils' class MongoDBAtlas_VectorStores implements INode { @@ -191,15 +191,17 @@ let mongoClientSingleton: MongoClient let mongoUrl: string const getMongoClient = async (newMongoUrl: string) => { + const driverInfo = { name: 'Flowise', version: (await getVersion()).version } + if (!mongoClientSingleton) { // if client does not exist - mongoClientSingleton = new MongoClient(newMongoUrl) + mongoClientSingleton = new MongoClient(newMongoUrl, { driverInfo }) mongoUrl = newMongoUrl return mongoClientSingleton } else if (mongoClientSingleton && newMongoUrl !== mongoUrl) { // if client exists but url changed mongoClientSingleton.close() - mongoClientSingleton = new MongoClient(newMongoUrl) + mongoClientSingleton = new MongoClient(newMongoUrl, { driverInfo }) mongoUrl = newMongoUrl return mongoClientSingleton } diff --git a/packages/components/src/utils.ts b/packages/components/src/utils.ts index e07bf8615..01c517162 100644 --- a/packages/components/src/utils.ts +++ b/packages/components/src/utils.ts @@ -772,3 +772,28 @@ export const prepareSandboxVars = (variables: IVariable[]) => { } return vars } + +let version: string +export const getVersion: () => Promise<{ version: string }> = async () => { + if (version != null) return { version } + + const checkPaths = [ + path.join(__dirname, '..', 'package.json'), + path.join(__dirname, '..', '..', 'package.json'), + path.join(__dirname, '..', '..', '..', 'package.json'), + path.join(__dirname, '..', '..', '..', '..', 'package.json'), + path.join(__dirname, '..', '..', '..', '..', '..', 'package.json') + ] + for (const checkPath of checkPaths) { + try { + const content = await fs.promises.readFile(checkPath, 'utf8') + const parsedContent = JSON.parse(content) + version = parsedContent.version + return { version } + } catch { + continue + } + } + + throw new Error('None of the package.json paths could be parsed') +}