【发布时间】:2025-11-28 20:35:01
【问题描述】:
我创建了一个猫鼬模式并添加了一些模式类型
const userSchema = new mongoose.Schema({
name: {
type: String,
required: [true, 'Please tell us your name']
},
email: {
type: String,
required: true,
unique: true,
lowercase: true,
validate: [validator.isEmail, 'please provide a email']
},
photo: String,
password: {
type: String,
required: [true, 'Please provide a password'],
minlength: 8,
select: false
},
passwordConfirm: {
type: String,
required: [true, 'Please Confirm your password'],
validate: {
// This only works on CREATE AND SAVE!!!
validator: function(el) {
return el === this.password
},
message: 'Passwords are not same'
}
},
passwordChangedAt: Date
});
然后我将数据分配给模型
{
"name" : "Abdullah",
"email" : "abdullah@gmail.com",
"password" : "pass1234",
"passwordConfirm" : "pass1234",
"passwordChangedAt" : "12-4-2021"
}
最后,“passwordChangedAt”属性没有显示在我的数据库中
【问题讨论】:
-
可能是日期格式,试试 ("12-04-2021" ------ "dd-mm-yyyy")
-
我已经尝试过这种格式
-
"passwordChangedAt" : new Date("4/12/2021");您需要使用特定格式在 mongo 中保存日期。
标签: node.js mongodb express mongoose mongoose-schema