我正在开发用于显示器,台式机,笔记本电脑,投影仪,打印机,扫描仪的库存应用。所以我想问,对此有什么好的结构?我应该为每个类别还是像一个类别创建一个模式
var Item = mongoose.model('Item', {
category: { type: String, minlength: 5, required: true, trim: true },
type: { type: String, minlength: 5, required: true, trim: true },
brand: { type: String, minlength: 5, required: true, trim: true },
model: { type: String, minlength: 5, required: true, trim: true },
serial: { type: String, minlength: 5, required: true, trim: true },
storage: { type: String, minlength: 5, required: true, trim: true },
graphics: { type: String, minlength: 5, required: true, trim: true },
ram: { type: String, minlength: 5, required: true, trim: true },
});
内存和图形仅适用于台式机和笔记本电脑。可以为全部创建一个架构,还是为每个类别创建架构?
答案 0 :(得分:0)
这很好,仅当对类别进行操作时(除台式机或笔记本电脑外),您可以在从文档中选择属性时忽略该属性
例如
Item.findOne({category: "printer"}).select("-graphics -ram");