mongoose-simpledb
mongoose-simpledb copied to clipboard
support multiple db instances
Now simpledb only works using one mongodb instance with one database. Would be nice if this could be extended to support multiple instances/dbs. Currently working on some projects where this might be of use (they are not using simpledb yet, but I want to make the transition).
Did you mean replica set or several indipendent databases?
Independant
Library have db
object linked to last connected DataBase, so if you don't use it - I think all be ok.
Try something like that:
var simpledb = require('mongoose-simpledb');
var db1Opts = { connectionString: 'mongodb://localhost/db1', modelsDir: './db1Models' };
var db2Opts = { connectionString: 'mongodb://localhost/db2', modelsDir: './db2Models' };
simpledb.init(db1Opts , function (err, db1) {
if (err) return console.error(err);
// You can safely assume that db is populated with your models.
db1.Comment.find({ blogPost: 123 }, ...):
});
simpledb.init(db2Opts, function (err, db2) {
if (err) return console.error(err);
// You can safely assume that db is populated with your models.
db2.Comment.find({ blogPost: 123 }, ...):
});