3

I have two databases that one affects the other one, so I wanted to see if there was a way to connect two both dbs so that one model can be associated to the other db where the other model can focus on a diff db.

Currently my models look like this:

var mongoose, Schema, Moduser, ObjectId, Project, bcrypt, SALT_WORK_FACTOR;
mongoose = require('mongoose');
Schema = mongoose.Schema;
ObjectId = mongoose.Schema.Types.ObjectId;
Project = require('../models/project.js');
bcrypt = require('bcryptjs');
SALT_WORK_FACTOR = 10;



Moduser = new Schema({
    email: { type: String, required: true, lowercase: true, index: {unique: true}},
    password: { type: String, unique: true}

}, {collection: "modusers"});

module.exports = mongoose.model('Moduser', Moduser);

and in my routes I call mongoose like so up top:

var mongoose = require('mongoose');
mongoose.connect("mongodb://connect1");

I want to be able to use in my routes file a function that can make use of both dbs... how do I add a second db and then target both dbs specifically - I was thinking maybe including them in the models, but was not sure how to implement it like so?

Lion789
  • 4,402
  • 12
  • 58
  • 96
  • Possible duplicate http://stackoverflow.com/q/19474712/3284355 – Molda Jun 02 '16 at 07:07
  • Molda the answers posted there are outdated... already looked at them. Also, calling both connections in the file causes error for the main answer... – Lion789 Jun 02 '16 at 07:14

0 Answers0