mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat(MongoDB Node): Add driver info to MongoDB nodes (#18615)
This commit is contained in:
@@ -153,8 +153,16 @@ export function stringifyObjectIDs(items: INodeExecutionData[]) {
|
||||
return items;
|
||||
}
|
||||
|
||||
export async function connectMongoClient(connectionString: string, credentials: IDataObject = {}) {
|
||||
export async function connectMongoClient(
|
||||
connectionString: string,
|
||||
nodeVersion: number,
|
||||
credentials: IDataObject = {},
|
||||
) {
|
||||
let client: MongoClient;
|
||||
const driverInfo = {
|
||||
name: 'n8n_crud',
|
||||
version: nodeVersion > 0 ? nodeVersion.toString() : 'unknown',
|
||||
};
|
||||
|
||||
if (credentials.tls) {
|
||||
const ca = credentials.ca ? formatPrivateKey(credentials.ca as string) : undefined;
|
||||
@@ -172,10 +180,10 @@ export async function connectMongoClient(connectionString: string, credentials:
|
||||
client = await MongoClient.connect(connectionString, {
|
||||
tls: true,
|
||||
secureContext,
|
||||
driverInfo,
|
||||
});
|
||||
} else {
|
||||
client = await MongoClient.connect(connectionString);
|
||||
client = await MongoClient.connect(connectionString, { driverInfo });
|
||||
}
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,9 @@ export class MongoDb implements INodeType {
|
||||
);
|
||||
}
|
||||
|
||||
const client = await connectMongoClient(connectionString, credentials);
|
||||
// Note: ICredentialTestFunctions doesn't have a way to get the Node instance
|
||||
// so we set the version to 0
|
||||
const client = await connectMongoClient(connectionString, 0, credentials);
|
||||
|
||||
const { databases } = await client.db().admin().listDatabases();
|
||||
|
||||
@@ -102,7 +104,8 @@ export class MongoDb implements INodeType {
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const credentials = await this.getCredentials('mongoDb');
|
||||
const { database, connectionString } = validateAndResolveMongoCredentials(this, credentials);
|
||||
const client = await connectMongoClient(connectionString, credentials);
|
||||
const nodeVersion = this.getNode().typeVersion;
|
||||
const client = await connectMongoClient(connectionString, nodeVersion, credentials);
|
||||
let returnData: INodeExecutionData[] = [];
|
||||
|
||||
try {
|
||||
@@ -110,7 +113,6 @@ export class MongoDb implements INodeType {
|
||||
|
||||
const items = this.getInputData();
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
const nodeVersion = this.getNode().typeVersion;
|
||||
|
||||
let itemsLength = items.length ? 1 : 0;
|
||||
let fallbackPairedItems: IPairedItemData[] | null = null;
|
||||
|
||||
@@ -3,7 +3,11 @@ import { Collection, MongoClient } from 'mongodb';
|
||||
import type { INodeParameters, WorkflowTestData } from 'n8n-workflow';
|
||||
|
||||
MongoClient.connect = async function () {
|
||||
const client = new MongoClient('mongodb://localhost:27017');
|
||||
const driverInfo = {
|
||||
name: 'n8n_crud',
|
||||
version: '1.2',
|
||||
};
|
||||
const client = new MongoClient('mongodb://localhost:27017', { driverInfo });
|
||||
return client;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user