这是我的代码..
var user_schema = new Schema({
name: String,
last_name: { type: String, required: true, maxlength: [50, "username not valid "], },
password: {
type: String,
minlength: [8, "El password is short"],
validate:{
validator:function (p) {
return this.password_confirmation == p
},
message: "password incorrect "
}
},
age: { Number, min: [17, "age < 17"], max: [75, "age > 75"] },
email: { type: String, require: " error email ",match:email_match },
date_of_birth: Date,
sex: { type: String, enum: { values: posibles_valores , message:"option no valid" } }
})
user_schema.virtual("password_confirmation").get(function () {
return this.p_c
}).set(function (password) {
this.p_c = password
})
user_schema.virtual("full_name").get(function () {
return this.name + this.last_name
}).set(function (full_name) {
var words = full_name.split(" ");
this.name = words[0];
this.last_name =words[1]
})
控制台中的错误消息是:
Project / node_modules / mongoose / lib / schema.js:614
throw new TypeError('Undefined type `' + name + '` at array `' + path +
^
TypeError: Undefined type `undefined` at array `age.min`
我不知道发生了什么,并且在验证时我的消息没有显示
答案 0 :(得分:0)
您的age
财产声明中有错误:
age: { type: Number, min: [17, "age < 17"], max: [75, "age > 75"] },
您错过了type
属性。