3 回答

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超1個(gè)贊
-app_root/--foo_app/---db_access.js---foo_db_connect.js---node_modules/----mongoose/--bar_app/---db_access.js---bar_db_connect.js---node_modules/----mongoose/
var mongoose = require('mongoose');mongoose.connect('mongodb://localhost/foo_db');module.exports = exports = mongoose;
var mongoose = require('mongoose');mongoose.connect('mongodb://localhost/bar_db');module.exports = exports = mongoose;
var mongoose = require("./foo_db_connect.js"); // bar_db_connect.js for bar app

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
createConnection()
能,會(huì),可以
var conn = mongoose.createConnection('mongodb://localhost/testA');var conn2 = mongoose.createConnection('mongodb://localhost/testB');// stored in 'testA' databasevar ModelA = conn.model('Model', new mongoose.Schema({ title : { type : String, default : 'model in testA database' }}));// stored in 'testB' databasevar ModelB = conn2.model('Model', new mongoose.Schema({ title : { type : String, default : 'model in testB database' }}));

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超6個(gè)贊
var Mongoose = require('mongoose').Mongoose;var instance1 = new Mongoose();instance1.connect('foo');var instance2 = new Mongoose();instance2.connect('bar');
添加回答
舉報(bào)