mongoose-simpledb icon indicating copy to clipboard operation
mongoose-simpledb copied to clipboard

support multiple db instances

Open hans-d opened this issue 8 years ago • 3 comments

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).

hans-d avatar Nov 09 '15 12:11 hans-d

Did you mean replica set or several indipendent databases?

Santinell avatar Nov 09 '15 12:11 Santinell

Independant

hans-d avatar Nov 09 '15 12:11 hans-d

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 }, ...):
});

Santinell avatar Nov 09 '15 12:11 Santinell