How to use the @nestjs/mongoose.MongooseModule.forRootAsync function in @nestjs/mongoose

To help you get started, we’ve selected a few @nestjs/mongoose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github autoai-org / AID / components / discovery / src / app.module.ts View on Github external
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { MongooseModule } from '@nestjs/mongoose';
import { ModelModule } from './model/model.module';
import { AuthModule } from './auth/auth.module';
import { UserModule } from './user/user.module';
import { SystemsModule } from './systems/systems.module'
import config from './config';

@Module({
  imports: [MongooseModule.forRootAsync({
    useFactory: async () => ({
      uri: config.MONGO_URI
    })
  }),
    ModelModule,
    AuthModule,
    UserModule,
    SystemsModule],
  controllers: [AppController],
  providers: [AppService],
})

export class AppModule { }
github jiayisheji / nest-cnode / src / core / core.module.ts View on Github external
import { resolve } from 'path';
import { MailConfig } from 'config/mail';
@Module({
    imports: [
        PassportModule.register({
            session: false,
        }),
        ConfigModule
            .resolveRootPath(resolve(__dirname, '../..'))
            .resolveEnvValidator(new ConfigValidate())
            .forRoot(
                resolve(__dirname, '..', 'config', '**', '!(*.d).{ts,js}'),
                {
                    path: `${process.env.NODE_ENV || 'development'}.env`,
                }),
        MongooseModule.forRootAsync({
            imports: [ConfigModule],
            useFactory: async (configService: ConfigService) => ({
                uri: configService.get('env.MONGODB_URI'),
                useNewUrlParser: true,
            }),
            inject: [ConfigService],
        }),
        MailerModule.forRootAsync({
            imports: [ConfigModule],
            useFactory: async (configService: ConfigService) => {
                return configService.get('mail');
            },
            inject: [ConfigService],
        }),
    ],
})
github ZhiXiao-Lin / nestify / apps / service / src / common / common.module.ts View on Github external
const event = new EventEmitter();

@Global()
@Module({
    imports: [
        ConfigModule.register(path.resolve(process.cwd(), 'dist/config', '**/!(*.d).js')),
        CacheModule.registerAsync({
            useFactory: (config: IConfigService) => config.get('cache'),
            inject: [CONFIG_SERVICE]
        }),
        LoggerModule.registerAsync({
            useFactory: (config: IConfigService) => config.get('logger'),
            inject: [CONFIG_SERVICE]
        }),
        EventBusModule.register({ event }),
        MongooseModule.forRootAsync({
            useFactory: (config: IConfigService) => config.get('mongo.connection'),
            inject: [CONFIG_SERVICE]
        }),
        CryptModule.registerAsync({
            useFactory: (config: IConfigService) => config.get('crypt'),
            inject: [CONFIG_SERVICE]
        }),
        NotificationModule,
        CoreModule
    ],
    providers: [ConfigProvider, CacheProvider, LoggerProvider, EventPublisherProvider, CryptProvider, NotificationProvider],
    exports: [
        CacheModule,
        NotificationModule,
        ConfigProvider,
        CacheProvider,
github nartc / nest-mean / server / src / app.module.ts View on Github external
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { Configuration } from './shared/configuration/configuration.enum';
import { ConfigurationService } from './shared/configuration/configuration.service';
import { SharedModule } from './shared/shared.module';
import { TodoModule } from './todo/todo.module';
import { UserModule } from './user/user.module';

@Module({
    imports: [SharedModule, MongooseModule.forRootAsync({
        imports: [SharedModule],
        useFactory: async (_configService: ConfigurationService) => ({
            uri: _configService.get(Configuration.MONGO_URI),
            retryDelay: 500,
            retryAttempts: 3,
            useFindAndModify: false,
            useNewUrlParser: true,
            useCreateIndex: true,
        }),
        inject: [ConfigurationService],
    }), UserModule, TodoModule],
    controllers: [AppController],
    providers: [AppService],
})
export class AppModule {
    static host: string;
github Kibibit / achievibit / src / dev-tools / in-memory-database.module.ts View on Github external
let mongod: MongoMemoryServer;
let uri: string;

async function testDBFactory() {
  mongod = new MongoMemoryServer();
  uri = await mongod.getConnectionString();
  await mongoose.connect(uri, {
    useNewUrlParser: true,
    useUnifiedTopology: true
  });
  return { uri };
}

@Module({
  imports: [
    MongooseModule.forRootAsync({
      useFactory: testDBFactory
    })
  ]
})
export class InMemoryDatabaseModule {
  static async closeDatabase() {
    await mongoose.connection.dropDatabase();
    await mongoose.connection.close();
    await mongod.stop();
    mongod = null;
    uri = null;
  }
}
github EricKit / nest-user-auth / src / app.module.ts View on Github external
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { MongooseModule, MongooseModuleOptions } from '@nestjs/mongoose';
import { UsersModule } from './users/users.module';
import { AuthModule } from './auth/auth.module';
import { join } from 'path';
import { ConfigModule } from './config/config.module';
import { ConfigService } from './config/config.service';

@Module({
  imports: [
    MongooseModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => {
        const options: MongooseModuleOptions = {
          uri: configService.mongoUri,
          useNewUrlParser: true,
          useCreateIndex: true,
          useFindAndModify: false,
          useUnifiedTopology: true,
        };

        if (configService.mongoAuthEnabled) {
          options.user = configService.mongoUser;
          options.pass = configService.mongoPassword;
        }

        return options;