我的导航架构中有以下对象:
const navItem = new Schema ({
"title": { type: string, unique: true, required: "A Title is req."},
.............
"badge": {
"label": "string",
"class": "string"
}
..............
})
虽然不需要徽章,但标签和班级是否存在徽章。
如何在我的猫鼬模式中正确显示可选徽章的此要求?
谢谢
答案 0 :(得分:1)
轻松解决方案....
const badgeSchema = new mongoose.Schema ({
badge: {
label: { type: string, required: true}
class: { type: string, required: true}
}
..............
})
const navItem = new Schema ({
"title": { type: string, unique: true, required: "A Title is req."},
.............
"badge": { type: badgeSchema, required: false}
..............
})