📌  相关文章
📜  单个 node.js 项目中的 Mongoose 和多个数据库 - 任何代码示例

📅  最后修改于: 2022-03-11 14:57:07.791000             🧑  作者: Mango

代码示例1
var conn      = mongoose.createConnection('mongodb://localhost/testA');
var conn2     = mongoose.createConnection('mongodb://localhost/testB');

// stored in 'testA' database
var ModelA    = conn.model('Model', new mongoose.Schema({
  title : { type : String, default : 'model in testA database' }
}));

// stored in 'testB' database
var ModelB    = conn2.model('Model', new mongoose.Schema({
  title : { type : String, default : 'model in testB database' }
}));