Advertisement
nodejsdeveloperskh

mongoose uses config service

Jun 2nd, 2021
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {
  2.     MongooseModuleOptions,
  3.     MongooseModuleAsyncOptions,
  4. } from '@nestjs/mongoose';
  5. import { ConfigModule, ConfigService } from '@nestjs/config';
  6.  
  7. class MongooseConfig {
  8.     static getMongooseConfigs(
  9.         configService: ConfigService,
  10.     ): MongooseModuleOptions {
  11.         return {
  12.             uri: configService.get<string>('mongodb.uri'),
  13.             useNewUrlParser: true,
  14.             useUnifiedTopology: true,
  15.         };
  16.     }
  17. }
  18.  
  19. const MongooseAsyncOptions: MongooseModuleAsyncOptions = {
  20.     connectionName: 'mongodb-database',
  21.     imports: [ConfigModule],
  22.     inject: [ConfigService],
  23.     useFactory: async (
  24.         configService: ConfigService,
  25.     ): Promise<MongooseModuleOptions> =>
  26.         MongooseConfig.getMongooseConfigs(configService),
  27. };
  28.  
  29. export { MongooseAsyncOptions };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement