title: How to change a Database connection dynamically with Request Scope Providers in Nestjs?
body: <p>Working on a project with <strong>Nestjs 6.x, Mongoose, Mongo</strong>, etc... 
  Regarding to the Back End, in my use case, I must change the connection of one of my <strong>databases</strong> depending of some <strong>conditions/parameters</strong> coming from some <strong>requests</strong>. </p>
  
  <p>Basically, I <strong>have</strong> this</p>
  
  <pre><code>mongoose.createConnection('mongodb://127.0.0.1/whatever-a', { useNewUrlParser: true })
  </code></pre>
  
  <p>and I want to <strong>change to</strong>, for example</p>
  
  <pre><code>mongoose.createConnection('mongodb://127.0.0.1/whatever-b', { useNewUrlParser: true })
  </code></pre>
  
  <p>Therefore, I have in Nestjs the first provider</p>
  
  <pre><code>export const databaseProviders = [
    {
      provide: 'DbConnectionToken',
      useFactory: async (): Promise&lt;typeof mongoose&gt; =&gt;
      await mongoose.createConnection('mongodb://127.0.0.1/whatever', { useNewUrlParser: true })
    }
  </code></pre>
  
  <p>I was researching for a while and I found out that in release <strong>Nestjs 6.x</strong> there are provider <strong>requests</strong> allowing me to modify dynamically <strong>Per-request</strong> the injection of some providers.</p>
  
  <p>Anyway, I don't know how to achieve my change neither if it is going to be working in case I'd achieve that</p>
  
  <p>Can anyone help or guide me?
  Many thanks in advance.</p>