typeorm-mongo-health
v1.0.6
Published
typeorm mongo health
Downloads
91
Maintainers
Readme
A health checker for mongodb in typeorm
Table of contents
Installation
npm install --save [email protected]
Usage
The simplest way to check mongo health
in typeorm is using typeorm-mongo-health
:
import { Injectable } from '@nestjs/common';
import { getConnection } from 'typeorm';
import { MongoHealh } from 'typeorm-mongo-health';
@Injectable()
export class HealthService {
constructor(
@Inject('DATA_SOURCE') private dataSource: DataSource,
private mongoHelath: MongoHealh,
) {}
async healthCheck(): Promise<any> {
// Get the MongoManager from the DataSource
const mongoManager = this.dataSource.manager;
const connection = mongoManager.connection;
const mongoHealth = await this.mongoHelath.mongoHealth(
connection, // typeorm connection
'mongodb-name', // mongo name
10000, // timeout millisecond
);
return mongoHealth;
}
}
Change Log
See Changelog for more information.
Contributing
Contributions welcome! See Contributing.
Author
Amir Kenarang (Amir Kenarang)
License
Licensed under the MIT License - see the LICENSE file for details.