0
我正在尋找具有引用變量子模型的父模型的最佳方法。有沒有辦法在保存父模型時設置引用,然後讓它自動填充孩子?如果不是,實現具有可變子字段的父模型的最佳方式是什麼。貓鼬變量模式參考
var ChildSchema1 = new Schema({
field1: String,
field2: String
});
var ChildSchema2 = new Schema ({
field3: Number,
field4: String
});
var ParentSchema = new Schema({
name: {type: String, required: true},
child_ref: {type: ObjectId, ref: ChildSchema1 OR ChildSchema2}
});