From e6eb1a84118e43f43015cc408b54680bc077a564 Mon Sep 17 00:00:00 2001 From: Alex Alloza Date: Fri, 4 Oct 2024 09:59:22 +0200 Subject: [PATCH] mongodb plain connection --- eda/eda_api/lib/module/excel/excel-sheet.controller.ts | 3 ++- .../services/connection/db-systems/mongodb-connection.ts | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/eda/eda_api/lib/module/excel/excel-sheet.controller.ts b/eda/eda_api/lib/module/excel/excel-sheet.controller.ts index b101f3a2..e6e28268 100644 --- a/eda/eda_api/lib/module/excel/excel-sheet.controller.ts +++ b/eda/eda_api/lib/module/excel/excel-sheet.controller.ts @@ -36,13 +36,14 @@ export class ExcelSheetController { const parsedUrl = new URL(databaseUrl?.url); //Transformar a datasource con todo inicializado a vacio const { host, port, password } = parsedUrl; + const config = { type: "mongodb", host: host.substring(0, host.indexOf(':')), port: Number(port), database: parsedUrl.pathname.substring(1), user: parsedUrl.username, - password, + password: parsedUrl.password, }; const mongoConnection = new MongoDBConnection(config); diff --git a/eda/eda_api/lib/services/connection/db-systems/mongodb-connection.ts b/eda/eda_api/lib/services/connection/db-systems/mongodb-connection.ts index 75f94a12..75265020 100644 --- a/eda/eda_api/lib/services/connection/db-systems/mongodb-connection.ts +++ b/eda/eda_api/lib/services/connection/db-systems/mongodb-connection.ts @@ -22,7 +22,12 @@ export class MongoDBConnection extends AbstractConnection { const user = this.config.user; const password = this.config.password; - this.connectUrl = `${type}://${user}:${password}@${host}:${port}/${db}?authSource=${db}`; + let credentialStr = ''; + if (user && password) { + credentialStr = `${user}:${password}@`; + } + + this.connectUrl = `${type}://${credentialStr}${host}:${port}/${db}?authSource=${db}`; const options = { useNewUrlParser: true, useUnifiedTopology: true }; const connection = await MongoClient.connect(this.connectUrl, options);