Skip to content

Commit

Permalink
Merge pull request #2548 from ElfoLiNk/typeorm-mongodb-ping
Browse files Browse the repository at this point in the history
change typeorm mongodb check
  • Loading branch information
BrunnerLivio authored Jul 16, 2024
2 parents 46f675c + 2f0e97d commit 1a655e4
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions lib/health-indicator/database/typeorm.health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,6 @@ export class TypeOrmHealthIndicator extends HealthIndicator {
}
}

private async checkMongoDBConnection(connection: any) {
return new Promise<void>((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
*
Expand All @@ -103,7 +81,9 @@ export class TypeOrmHealthIndicator extends HealthIndicator {
let check: Promise<any>;
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');
Expand Down

0 comments on commit 1a655e4

Please sign in to comment.