node.js - How do I use mongoose to connect to two different databases? -
i have 2 databases 1 affects other one, wanted see if there way connect 2 both dbs 1 model can associated other db other model can focus on diff db.
currently models 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 routes call mongoose top:
var mongoose = require('mongoose'); mongoose.connect("mongodb://connect1");
i want able use in routes file function can make use of both dbs... how add second db , target both dbs - thinking maybe including them in models, not sure how implement so?