Here is my code..
这是我的代码..
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]
})
Error message in console is:
控制台中的错误消息是:
Project/node_modules/mongoose/lib/schema.js:614
项目/ node_modules /猫鼬/ lib中/ schema.js:614
throw new TypeError('Undefined type `' + name + '` at array `' + path +
^
TypeError: Undefined type `undefined` at array `age.min`
I don't know that happend and my message is not displaying when it is validating
我不知道发生了什么,我的消息在验证时没有显示
1 个解决方案
#1
0
You have a mistake in your age
property declaration:
您的年龄属性声明中有错误:
age: { type: Number, min: [17, "age < 17"], max: [75, "age > 75"] },
You were missing the type
property.
你错过了type属性。
#1
0
You have a mistake in your age
property declaration:
您的年龄属性声明中有错误:
age: { type: Number, min: [17, "age < 17"], max: [75, "age > 75"] },
You were missing the type
property.
你错过了type属性。