0

How to call multiple Database table in same Model JS File Let's Say

var mongoose = require('./node_modules/mongoose');

mongoose.connect('mongodb://localhost/_db1');
module.exports = exports = mongoose;

// I know this overwrites
// Something like calling with different variable name
// Say mongoosedb1, mongoosedb2
// Still if do that we have to pass the library to both variables
// Any other possible ways??

mongoose.connect('mongodb://localhost/_db2');
module.exports = exports = mongoose;

I am not sure whether this is making sense, Could you anyone please give some suggestions, I am new to this MEAN Stack framework.

Thanks in Advance!!

Vishnu
  • 11,614
  • 6
  • 51
  • 90
Ashokprakash
  • 23
  • 1
  • 9
  • http://stackoverflow.com/questions/19474712/mongoose-and-multiple-database-in-single-node-js-project – Vishnu Sep 10 '15 at 10:57
  • No that is not my question :), That is under a single node project. I am asking to access for a signal JS file, which has the db connections, under model folder. – Ashokprakash Sep 10 '15 at 11:03
  • Are you possibly asking "How to use the same model on two database connections, within the same application?", which would seem a lot clearer title and a base for rethinking your explanation in your question. But I should also add that "technically" is not not the "model" that would be shared but the "schema" to "two" models, being one for each database connection. – Blakes Seven Sep 10 '15 at 11:12
  • Yeah well "just using the title I suggested" does not really make the question that much clearer in itself without clarifying the content a little bit. Also a "search engine" might even help you with the phrase as suggested in the title. – Blakes Seven Sep 10 '15 at 11:36

0 Answers0