我想为mongoose中的字段设置严格的值,例如在下面的模式中
var Option_Sets = new Schema({
setId: {
type: mongoose.Schema.ObjectId,
default: mongoose.Types.ObjectId,
required: true,
dropDups: true,
index: true
},
setName: { type: String },
scope: String,
components: [Schema.Types.Mixed]
});
我想设置范围字段只能在范围数组中使用一个
var scopes = ["Global", "Store View", "Website"];
有人可以帮我举一个例子并指导我如何做到这一点。 最好先谢谢
答案 0 :(得分:2)
为了执行此尝试枚举:
var Option_Sets = new Schema({
setId: {
type: mongoose.Schema.ObjectId,
default: mongoose.Types.ObjectId,
required: true,
dropDups: true,
index: true
},
setName: { type: String },
scope: {
type: String,
enum: ["Global", "Store View", "Website"]
},
components: [Schema.Types.Mixed]
});