mongoose right usage of multiple databases? <p>I have multiple <code>mongodb</code> connections in my project:</p> <pre><code>// db.coffee conn1 = mongoose.createConnection "mongodb://192.168.1.193/test" conn2 = mongoose.createConnection "mongodb://92.168.1.81/position" </code></pre> <p>I have a model named <code>PositionNoCity</code> which belongs to <code>conn2</code> and a model named <code>A</code> which belongs to <code>conn1</code>:</p> <pre><code>// a.coffee ASchema = new Schema { a: Number }, {collection: 'test'} mongoose.model 'A', ASchema // pos.coffee PositionNoCitySchema = new Schema { position_id: String, job_forward_stats: [{forward_position_num: Number, forward_position: String, forward_position_ratio: Number}], }, {collection: 'position_indicators_no_city'} mongoose.model 'PositionNoCity', PositionNoCitySchema </code></pre> <p>Now I want to use these models:</p> <pre><code>require './db' require './pos' require './a' mongoose = require 'mongoose' // I have to point out which connection to use here, but with index the code is very very bad A = mongoose.connections[1].model('A') PositionNoCity = mongoose.connections[2].model('PositionNoCity') PositionNoCity.findOne({position_id: "aaa"}).then(console.log).catch(console.log) A.findOne({'a': 1}).then(console.log).catch(console.log) </code></pre> <p>I have two questions:</p> <ol> <li>I just connect 2 times, why 3 connections?</li> <li>if I replace <code>mongoose.connections[2].model</code> with <code>mongoose.model</code>, I run failed. Anyway, <code>mongoose.connections[2].model</code> must be replaced somehow, so how to replace?</li> </ol>