【发布时间】:2022-10-07 21:11:58
【问题描述】:
我在这里遇到了一些问题,我尝试只存储一个对象,无论是学校、大学还是工作,但猫鼬会自动创建另外两个对象。
如何省略其他对象。在这里我应该使用default
let mySchema = new Schema({
"type": { type: String, default: "" }, // school or college or work
"school": {
'name':{ type: String, default: "" },
'parent':{ type: String, default: "" },
'address':{ type: String, default: "" },
'email_id':{ type: String, default: "" },
'phone_no':{ type: String, default: "" },
},
"college": {
'name':{ type: String, default: "" },
'friend':{ type: String, default: "" },
'address':{ type: String, default: "" },
'email_id':{ type: String, default: "" },
'phone_no':{ type: String, default: "" },
},
"work": {
'name':{ type: String, default: "" },
'colleague':{ type: String, default: "" },
'address':{ type: String, default: "" },
'email_id':{ type: String, default: "" },
'phone_no':{ type: String, default: "" },
},
});
【问题讨论】:
标签: javascript node.js mongodb mongoose mongoose-schema