title: How to connect to specific database with Mongoose and node?
body: <p>I'm learning how to use Mongoose and there's something I don't understand - how can I connect to specific database and collection in my cluster?</p>
  
  <p>I have 5 different databases and each database have few different collections</p>
  
  <p>When I was using pure Mongo client - the way the show it in official documentation, I connected like that:</p>
  
  <pre><code>const MongoClient = require('mongodb').MongoClient;
  const uri = process.env.mongo_connection_string;
  
  const client = new MongoClient(uri, { useNewUrlParser: true });
  client.connect(err =&gt; {
    const collection = client.db("database_name").collection("collection_name");
  
         // Do some work here in the selected database and the selected collection
    client.close();
  });
  </code></pre>
  
  <p>Now I want to use Mongoose to practice. So in my app.js to establish the connection I do:</p>
  
  <pre><code>mongoose.connect(process.env.mongo_connection_string , {useNewUrlParser: true})
  .then( () =&gt; console.log("Connection established"))
  .catch(err =&gt; console.log(err))
  </code></pre>
  
  <p>Then I have created a schema for one of the objects I want to store in the database. </p>
  
  <pre><code>const mongoose = require('mongoose')
  
  const UserSchema = new mongoose.Schema({
  
      name: {
          type: String,
          required: true
      },
      email: {
          type: String,
          required: true
      }
  })
  
  const User = mongoose.model('User', UserSchema)
  module.exports = User
  </code></pre>
  
  <p>How do I associate this model with the database and the collection I need?</p>