title: Mongoose multiple connections
body: <p>Currently I have this code for my connection <strong>mongoose.js</strong>:</p>
  
  <pre><code>var mongoose = require('mongoose');
  var uriUtil = require('mongodb-uri');
  var mongodbUri = 'mongodb://localhost/db_name';
  var mongooseUri = uriUtil.formatMongoose(mongodbUri);
  mongoose.connect(mongooseUri);
  module.exports = mongoose;
  </code></pre>
  
  <p>File that requires the connection is <strong>test.js</strong>:</p>
  
  <pre><code>var mongoose = require('../model/mongoose');
  var schema = mongoose.Schema({...});
  </code></pre>
  
  <hr>
  
  <hr>
  
  <p>How can I update mongoose.js to use multiple connections with mongoose.createConnection(...) function? </p>
  
  <p>I start with changes only for one connection when I do changes like that:</p>
  
  <pre><code>var mongoose = require('mongoose');
  mongoose.createConnection('mongodb://localhost/db_name');
  mongoose.open('localhost');
  module.exports = mongoose;
  </code></pre>
  
  <p>I get "undefined is not a function".
  If I use this code:</p>
  
  <pre><code>var mongoose = require('mongoose');
  db = mongoose.createConnection('mongodb://localhost/db_name');
  db.open('localhost');
  module.exports = mongoose;
  </code></pre>
  
  <p>I get "Error: Trying to open unclosed connection"</p>
  
  <p>Any advice?</p>