Skip to content

Commit

Permalink
feat(typeorm): change typeorm mongodb check
Browse files Browse the repository at this point in the history
  • Loading branch information
ElfoLiNk committed May 2, 2024
1 parent 46f675c commit 2f0e97d
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 2f0e97d

Please sign in to comment.