mongoose-connect

Easy way to connect to the MongoDB database. Multiple databases.

mongoose-connect

Easy way to connect to the MongoDB database. Multiple databases.

npm install mongoose-connect
// prepare the data
var Models = [
    require('./models/ModelB'), // model in another file
    {
        name   : 'ModelNameA', // <- you will get the models by this name ***
        schema : new mongoose.Schema({})
    }
]
var mongoose            = require('mongoose');
var databaseName        = 'database-name'; // whatever you want
var mongooseConnect     = require('mongoose-connect');
var mongooseConnectData = mongooseConnect.connect(databaseName, Models, mongoose);
var connection          = mongooseConnectData.connection;
var models              = mongooseConnectData.models;

// ModelNameA refers to ***
models.ModelNameA.findOne({...})