this.schema = new Schema({
telephoneNumber: {type: String, required: true},
activationCode: {type: Number},
timeOfCreationCode: {type: Number},
stateOfActivationProcess: {type: Boolean},
typeOfCar: {type: String},
birthDay: {type: String},
gender: {type: String},
workingStatus: {type: Boolean},
minDownPaymentAgreeOrNot: {type: Boolean},
workingExperience: {type: String},
monthlyIncome: {type: String},
confirmMonthlyIncome: {type: Boolean},
whyUserNeedCar: {
type: Array,
**enum : enumList,**
require : true
},
userMonthlyBudget : {type : String}
});
错误:
enum
只能在字符串数组上设置,而不能在混合字符串上设置 在SchemaArray.enum(C:\ carsapp \ node_modules \ mongoose \ lib \ schema \ array.js:134:11) 在SchemaArray.SchemaType(C:\ carsapp \ node_modules \ mongoose \ lib \ schematype.js:55:18) 在新的SchemaArray(C:\ carsapp \ node_modules \ mongoose \ lib \ schema \ array.js:85:14) 在Function.Schema.interpretAsType(C:\ carsapp \ node_modules \ mongoose \ lib \ schema.js:580:12) 在Schema.path(C:\ carsapp \ node_modules \ mongoose \ lib \ schema.js:460:29) 在Schema.add(C:\ carsapp \ node_modules \ mongoose \ lib \ schema.js:341:12) 在新架构(C:\ carsapp \ node_modules \ mongoose \ lib \ schema.js:89:10) 在新的UserDbCollection(C:\ carsapp \ models \ user \ user.js:9:23) 在对象。 (C:\ carsapp \模型\用户\ user.js的:62:28) 在Module._compile(module.js:643:30) at Object.Module._extensions..js(module.js:654:10) 在Module.load(module.js:556:32) 在tryModuleLoad(module.js:499:12) 在Function.Module._load(module.js:491:3) 在Module.require(module.js:587:17) at require(internal / module.js:11:18)
答案 0 :(得分:2)
查看mongoose documentation枚举只能与字符串一起使用,因为您向我们展示的堆栈跟踪说。
Error: enum can only be set on an array of strings
请看以下示例:
drink: {
type: String,
enum: ['Coffee', 'Tea'],
required: function() {
return this.bacon > 3;
}
}