As an example, I want to have food categories, sub categories and the actual menu items themselves. All menu items have to have a category, but not all have to have a sub-category.
So, something like:
Example of category only:
Hamburgers
- Bacon and cheese
- Chicken
Example of category and sub-category:
Pizza
Traditional
- Cheese and mushroom
- Tomato and ham
Deluxe
- Bacon, ham, salami, steak
This means the sub category is optional. So, when building the form to add a menu item, should there be an option for none on the subcategory or if nothing is selected from the dropdown menu would it be fine to insert an empty string into the database?
This is what my schema looks like but not sure if it is right for what I need.
const menuSchema = new mongoose.Schema({
name: {
type: String,
required: true,
minlength: 5,
maxlenth: 255
},
description: {
type: String,
required: true,
minlength: 5,
maxlength: 255
},
price: {
type: Number,
required: true,
min: 0
},
category: {
type: categorySchema,
required: true
},
subcategory: {
type: subcategorySchema
}
});
const Menu = mongoose.model("Menu", menuSchema);
The category and subcategory schema are pretty much the same but would it be better to have 2 separate schemas for category and subcategory or have just a categories schema with an embedded subcategory within it or what is the best way to do this?
const categorySchema = new mongoose.Schema({
name: {
type: String,
required: true,
minlength: 5,
maxlength: 255
}
});
const Category = mongoose.model("Category", categorySchema);