Skip to content

Commit 9e88c45

Browse files
authored
feat: add driverInfo to mongodb component (#2779)
* feat: add driverInfo to mongodb component NODE-6240 * chore: add a getVersion utility function
1 parent 363d1bf commit 9e88c45

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

packages/components/nodes/vectorstores/MongoDBAtlas/MongoDBAtlas.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MongoDBAtlasVectorSearch } from '@langchain/mongodb'
44
import { Embeddings } from '@langchain/core/embeddings'
55
import { Document } from '@langchain/core/documents'
66
import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams, IndexingResult } from '../../../src/Interface'
7-
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
7+
import { getBaseClasses, getCredentialData, getCredentialParam, getVersion } from '../../../src/utils'
88
import { addMMRInputParams, resolveVectorStoreOrRetriever } from '../VectorStoreUtils'
99

1010
class MongoDBAtlas_VectorStores implements INode {
@@ -191,15 +191,17 @@ let mongoClientSingleton: MongoClient
191191
let mongoUrl: string
192192

193193
const getMongoClient = async (newMongoUrl: string) => {
194+
const driverInfo = { name: 'Flowise', version: (await getVersion()).version }
195+
194196
if (!mongoClientSingleton) {
195197
// if client does not exist
196-
mongoClientSingleton = new MongoClient(newMongoUrl)
198+
mongoClientSingleton = new MongoClient(newMongoUrl, { driverInfo })
197199
mongoUrl = newMongoUrl
198200
return mongoClientSingleton
199201
} else if (mongoClientSingleton && newMongoUrl !== mongoUrl) {
200202
// if client exists but url changed
201203
mongoClientSingleton.close()
202-
mongoClientSingleton = new MongoClient(newMongoUrl)
204+
mongoClientSingleton = new MongoClient(newMongoUrl, { driverInfo })
203205
mongoUrl = newMongoUrl
204206
return mongoClientSingleton
205207
}

packages/components/src/utils.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,3 +772,28 @@ export const prepareSandboxVars = (variables: IVariable[]) => {
772772
}
773773
return vars
774774
}
775+
776+
let version: string
777+
export const getVersion: () => Promise<{ version: string }> = async () => {
778+
if (version != null) return { version }
779+
780+
const checkPaths = [
781+
path.join(__dirname, '..', 'package.json'),
782+
path.join(__dirname, '..', '..', 'package.json'),
783+
path.join(__dirname, '..', '..', '..', 'package.json'),
784+
path.join(__dirname, '..', '..', '..', '..', 'package.json'),
785+
path.join(__dirname, '..', '..', '..', '..', '..', 'package.json')
786+
]
787+
for (const checkPath of checkPaths) {
788+
try {
789+
const content = await fs.promises.readFile(checkPath, 'utf8')
790+
const parsedContent = JSON.parse(content)
791+
version = parsedContent.version
792+
return { version }
793+
} catch {
794+
continue
795+
}
796+
}
797+
798+
throw new Error('None of the package.json paths could be parsed')
799+
}

0 commit comments

Comments
 (0)