title: Nest js mongoose log connection event
body: <p>I do something like this in express to log mongodb connection events.</p>
  <pre class="lang-js prettyprint-override"><code>mongoose
    .connect(process.env.DATABASE, {
      useNewUrlParser: true,
      useFindAndModify: false
    })
    .then(() =&gt; console.log('connect to DB successfully :)'));
  
  mongoose.connection.on('error', err =&gt; {
    console.log('DB connection failed');
  });
  
  mongoose.connection.on('disconnected', () =&gt; {
    console.log('DB disconnected');
  });
  
  mongoose.connection.on('reconnected', () =&gt; {
    console.log('DB reconnected');
  });
  </code></pre>
  <p>I want something like that in Nest js but I can't do that.
  here is my nest js code to connect to mongodb.</p>
  <pre class="lang-js prettyprint-override"><code>import { Module } from '@nestjs/common';
  import { ConfigModule, ConfigService } from '@nestjs/config';
  import { MongooseModule } from '@nestjs/mongoose';
  import { AppController } from './app.controller';
  import { AppService } from './app.service';
  
  @Module({
    controllers: [AppController],
    providers: [AppService],
    imports: [
      MongooseModule.forRootAsync({
        imports: [ConfigModule],
        useFactory: async (configService: ConfigService) =&gt; ({
          uri: configService.get&lt;string&gt;('dbConnectionString'),
          user: configService.get&lt;string&gt;('DB_USER'),
          pass: configService.get&lt;string&gt;('DB_PASS')
        }),
        inject: [ConfigService]
      })
    ]
  })
  export class AppModule {}
  </code></pre>