Skip to content
This repository has been archived by the owner on Jul 14, 2019. It is now read-only.

support multiple db instances #20

Open
hans-d opened this issue Nov 9, 2015 · 3 comments
Open

support multiple db instances #20

hans-d opened this issue Nov 9, 2015 · 3 comments

Comments

@hans-d
Copy link

hans-d commented Nov 9, 2015

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

@Santinell
Copy link
Contributor

Did you mean replica set or several indipendent databases?

@hans-d
Copy link
Author

hans-d commented Nov 9, 2015

Independant

@Santinell
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants