Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建良好的mongodb模式_Mongodb_Mongoose_Mongoose Schema - Fatal编程技术网

创建良好的mongodb模式

创建良好的mongodb模式,mongodb,mongoose,mongoose-schema,Mongodb,Mongoose,Mongoose Schema,我正在为显示器、台式机、笔记本电脑、投影仪、打印机、扫描仪开发一个库存应用程序。所以我想问,什么是一个好的结构?我应该为每个类别或类似的类别创建一个模式吗 var Item = mongoose.model('Item', { category: { type: String, minlength: 5, required: true, trim: true }, type: { type: String, minlength: 5, required: true, trim: true

我正在为显示器、台式机、笔记本电脑、投影仪、打印机、扫描仪开发一个库存应用程序。所以我想问,什么是一个好的结构?我应该为每个类别或类似的类别创建一个模式吗

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 },
});

ram和图形仅适用于台式机和笔记本电脑。可以为所有类别创建一个模式吗?或者应该为每个类别创建一个模式吗?

这很好,仅当在let say category Is anything(假设类别是除桌面或笔记本电脑以外的任何东西)上执行操作时,您可以在从文档中选择属性时忽略该属性

比如说

Item.findOne({category: "printer"}).select("-graphics -ram");