为猫鼬中的字段设置严格值
Set strict value for a field in mongoose
我想为 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]
});
我想设置scope字段在scope数组中只能取一个
var scopes = ["Global", "Store View", "Website"];
有人可以帮我举个例子并指导我如何去做吗?
提前致谢
为了执行这个尝试枚举:
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]
});
我想为 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]
});
我想设置scope字段在scope数组中只能取一个
var scopes = ["Global", "Store View", "Website"];
有人可以帮我举个例子并指导我如何去做吗? 提前致谢
为了执行这个尝试枚举:
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]
});