如果我想说一个服装网站,上面有产品,并且每个产品都有一个类别,我会试图了解两者之间的区别。
将类别设置为架构并将其粘贴到产品架构之间有什么区别?
var categorySchema = new mongoose.Schema({
name: String
});
var productSchema = new mongoose.Schema({
name: String,
category: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'category'
},
name: String
},
price: Number,
description: String
})
或者只是使类别和枚举类似:
var productSchema = new mongoose.Schema({
name: String,
category: {
type: String,
enum:['men', 'women', 'children']
},
price: Number,
description: String
})
有什么变化???什么是更好/认为更好的编码?
谢谢