@xnestjs/mongodb
v1.13.1
Published
NestJS extension library for MongoDb
Readme
@xnestjs/mongodb
NestJS extension library for MongoDB
Install
npm install @xnestjs/mongodb
# or using yarn
yarn add @xnestjs/mongodbUsage
Register sync
An example of nestjs module that import the @xnestjs/mongodb
// module.ts
import { Module } from '@nestjs/common';
import { MongoModule } from '@xnestjs/mongodb';
@Module({
imports: [
MongodbModule.forRoot({
useValue: {
url: 'https://mydbserver:27017',
database: 'test',
},
}),
],
})
export class MyModule {}Register async
An example of nestjs module that import the @xnestjs/mongodb async
// module.ts
import { Module } from '@nestjs/common';
import { MongoModule } from '@xnestjs/mongodb';
@Module({
imports: [
MongodbModule.forRootAsync({
inject: [ConfigModule],
useFactory: (config: ConfigService) => ({
url: config.get('MONGODB_URL'),
database: config.get('MONGODB_DATABASE'),
}),
}),
],
})
export class MyModule {}Environment Variables
The library supports configuration through environment variables. Environment variables below is accepted. All environment variables starts with prefix (MONGODB_). This can be configured while registering the module.
