📜  猫鼬填充不起作用 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:39.659000             🧑  作者: Mango

代码示例3
/*Beware that when using .populate() you MUST
provide the model as mongoose will only "find"
models on the same connection. ie where:*/

var db1 = mongoose.createConnection('mongodb://localhost:27017/gh3639');
var db2 = mongoose.createConnection('mongodb://localhost:27017/gh3639_2');
var userSchema = mongoose.Schema({
  "name": String,
  "email": String
});

var customerSchema = mongoose.Schema({
  "name" : { type: String },
  "email" : [ String ],
  "created_by" : { type: mongoose.Schema.Types.ObjectId, ref: 'users' },
});

var User = db1.model('users', userSchema);
var Customer = db2.model('customers', customerSchema);