是否可以使用 enum
验证在 type: [String]
?
例子:
var permitted = ['1','2','3'];
var exampleSchema = new Schema({
factors: {
type: [String],
enum: permitted,
required: "Please specify at least one factor."
}
});
我原以为
factors
只能包含 permitted
中的值.
最佳答案
这对我来说很好用 ( mongoose@4.1.8
)
var schema = new mongoose.Schema({
factors: [{type: String, enum: ['1', '2', '3'], required: ...}]
...
})
注意我使用的是对象数组
关于arrays - Mongoose 枚举字符串数组验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30783179/