title: How do I close a specific database connection in mongoose
body: <p>In my app I have two database connections open. One of the connections is for the standard development database. The second connection is for a seperate database that I specifically use for testing. </p>
  
  <p>Let's say the first connection is open and my app is running, and I decide I want to run my tests. The first test that runs opens the second connection, or closes it if it already exists.</p>
  
  <pre><code>import mongoose from 'mongoose';
  import 'dotenv/config';
  
  mongoose.Promise = global.Promise;
  
  describe('Mocha testing setup', function() {
    it('Connect to testing database and clear old data', function(done) {
      mongoose.connect(process.env.DB_TEST).then(db =&gt; {
        done();
      }).catch(err =&gt; {
        mongoose.connection.close().then( =&gt; {
          console.log('Testing database has been closed.');
        }).catch(done);
      });
    })
  })
  </code></pre>
  
  <p>When I run:</p>
  
  <pre><code>mongoose.connection.close()
  </code></pre>
  
  <p>How can I be certain that it will not close the first connection. I need to be certain that it will close the connection to the testing database not the development database. </p>