title: Nestjs: Unable to connect mongo asynchronously
body: <p>I am unable to connect to mongodb asynchronously. Please let me know what am I doing wrong.</p>
  <p><strong>MongoConfig</strong> file:</p>
  <pre><code>import { MongooseModuleOptions } from '@nestjs/mongoose';
  
  export default (): { mongoConfig: MongooseModuleOptions } =&gt; ({
    mongoConfig: {
      uri: process.env.DB_URI,
      connectionName: 'learn-nest',
      useCreateIndex: true,
      useUnifiedTopology: true,
      useFindAndModify: false,
      useNewUrlParser: true,
    },
  });
  
  </code></pre>
  <p>Here is the code written inside of <strong>App Module</strong></p>
  <pre><code>import { Module } from '@nestjs/common';
  import { AppController } from './app.controller';
  import { AppService } from './app.service';
  import { MongooseModule } from '@nestjs/mongoose';
  import { ConfigModule, ConfigService } from '@nestjs/config';
  
  @Module({
    imports: [
      ConfigModule.forRoot({
        envFilePath: ['.env'],
        isGlobal: true,
        cache: true,
      }),
      MongooseModule.forRootAsync({
        useFactory: (configService: ConfigService): any =&gt; {
          configService.get('mongoConfig');
        },
        inject: [ConfigService],
      }),
    ],
    controllers: [AppController],
    providers: [AppService],
  })
  export class AppModule {}
  
  </code></pre>
  <p>This is the error that it throws:</p>
  <p><strong>&quot;Cannot destructure property 'retryAttempts' of 'mongooseModuleOptions' as it is undefined&quot;</strong></p>
  <p>I do not understand why it's throwing this error because, 'retryAttempts' is an optional property in <strong>MongooseModuleOptions interface.</strong></p>
  <p><strong>MongooseModuleInterface</strong></p>
  <pre><code>export interface MongooseModuleOptions extends ConnectOptions, Record&lt;string, any&gt; {
      uri?: string;
      retryAttempts?: number;
      retryDelay?: number;
      connectionName?: string;
      connectionFactory?: (connection: any, name: string) =&gt; any;
  }
  </code></pre>