mongoose-connect
v0.0.3
Published
Easy way to connect to the MongoDB database. Multiple databases.
Downloads
74
Maintainers
Readme
mongoose-connect
Easy way to connect to the MongoDB database. Multiple databases.
Install
npm install mongoose-connect
How to use
// 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({...})