@nestutils/mongodb
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Nest Logo

@nestutils/mongodb

Description

This NestJS Module can be used to connect with MongoDB and provide common connection across application/Specified Modules.

Installation

In your existing NestJS-based project:

$ npm install --save @nestutils/mongodb

Usage

To Use MongoDB Client synchronously, one can use below configuration:

import { Module } from '@nestjs/common'
import { MongoClientModule } from '@nestutils/config-client'
@Module({
    imports: [
      MongoClientModule.forRoot({
        uri: '************' // MongoDB SRV Uri, which will be used to connect with DB Instance.
        dbName: '***********' // Database Name, which needs to be connected default with connection.
        connectionName: '**********' // Name of current connection, which further can be used for DI.
        clientOptions: {'******': '****', '*****': '*****'}  // Connection options, which will be used to connect with MongoDB.
    }),
      ]
})
export class AppModule {}

To Use MongoDB Client asynchronously, one can use below configuration:

import { Module } from '@nestjs/common'
import { MongoClientModule } from '@nestutils/config-client'
@Module({
    imports: [
      MongoClientModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: (configService: ClientConfigService) => ({
        uri: configService.uri,
        dbName: configService.dbName
    }),
    inject: [ConfigService]
    }),
      ]
})
export class AppModule {}

Contributions

Any suggestions, issues, bug-fixes, PR's are most welcomed. Thanks.

Note

This project is currently in active development 🚧. Breaking changes are expected.

Package Sidebar

Install

npm i @nestutils/mongodb

Weekly Downloads

3

Version

0.0.2

License

MIT

Unpacked Size

21.4 kB

Total Files

20

Last publish

Collaborators

  • belwalpb