From 2f0e97d77c53826012bfe10ebd2ed111e0445cd4 Mon Sep 17 00:00:00 2001 From: "matteo.gazzetta" Date: Thu, 2 May 2024 22:43:50 +0200 Subject: [PATCH] feat(typeorm): change typeorm mongodb check --- .../database/typeorm.health.ts | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/lib/health-indicator/database/typeorm.health.ts b/lib/health-indicator/database/typeorm.health.ts index c8f5eaa4d..5bed3cad3 100644 --- a/lib/health-indicator/database/typeorm.health.ts +++ b/lib/health-indicator/database/typeorm.health.ts @@ -70,28 +70,6 @@ export class TypeOrmHealthIndicator extends HealthIndicator { } } - private async checkMongoDBConnection(connection: any) { - return new Promise((resolve, reject) => { - const driver = connection.driver; - const url = connection.options.url - ? connection.options.url - : driver.buildConnectionUrl(connection.options); - - // FIXME: Hacky workaround which uses the native MongoClient - driver.mongodb.MongoClient.connect( - url, - driver.buildConnectionOptions(connection.options), - ) - .catch((err: Error) => reject(new MongoConnectionError(err.message))) - .then((client: TypeOrm.MongoClient) => client.close()) - - // Noop when trying to close a closed connection - // eslint-disable-next-line @typescript-eslint/no-empty-function - .catch(() => {}) - .then(() => resolve()); - }); - } - /** * Pings a typeorm connection * @@ -103,7 +81,9 @@ export class TypeOrmHealthIndicator extends HealthIndicator { let check: Promise; switch (connection.options.type) { case 'mongodb': - check = this.checkMongoDBConnection(connection); + check = (connection.driver as any).queryRunner.databaseConnection + .db() + .command({ ping: 1 }); break; case 'oracle': check = connection.query('SELECT 1 FROM DUAL');