我是猫鼬的新手,很抱歉,如果我的问题很愚蠢。
我有以下架构:
const mongoose = require('mongoose')
const restaurantSchema = mongoose.Schema({
owner_id: {
type: mongoose.Schema.Types.ObjectId,
required: true
},
name: {
type: String,
required: true,
unique: true
},
phone: {
type: String,
required: true
},
street: {
type: String,
required: true
},
city: {
type: String,
required: true
},
state: {
type: String,
required: true
},
zip: {
type: String,
required: true
},
image: String,
cuisine: {
type: String,
required: true
},
sections: [
{
id: mongoose.Schema.Types.ObjectId,
name: {
type: String,
unique: true
},
menus : [
{
id: mongoose.Schema.Types.ObjectId,
name: {
type: String,
required: true,
unique: true
},
description: String,
price: {
type: Number,
required: true
},
image: String
}
]
}
]
});
餐厅可能有很多部分,而这些部分又可能有很多菜单。要求如下:
我使节名和菜单名唯一,但我仍然可以用相同的名字创建节和菜单。我知道我的架构定义可能是错误的,并且方法本身可能是错误的。
有哪些方法可以实现?