1.0.6 • Published 1 year ago

typeorm-mongo-health v1.0.6

Weekly downloads
5
License
MIT
Repository
github
Last release
1 year ago

A health checker for mongodb in typeorm

Table of contents

Installation

npm install --save typeorm-mongo-health@1.0.5

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.