Javascript mongoose不验证更新的部件
我已经创建了userSchema mongoose模型,下面是我模型的相关部分:Javascript mongoose不验证更新的部件,javascript,node.js,mongodb,mongoose,Javascript,Node.js,Mongodb,Mongoose,我已经创建了userSchema mongoose模型,下面是我模型的相关部分: password: { type: String, required: [true, "Please enter a password"], minlength: [6, "Minimum password length is 6 characters"], }, 但当我更新保存到数据库的记录时: userSchema.statics.upd
password: {
type: String,
required: [true, "Please enter a password"],
minlength: [6, "Minimum password length is 6 characters"],
},
但当我更新保存到数据库的记录时:
userSchema.statics.updated = async function (_id, field, value) {
const user = await this.updateOne(
{ _id },
{
$set: { [field]: value, updatedAt: Date.now() },
}
);
};
验证不起作用。我尝试添加{runValidators:true}
或创建类似的中间件
userSchema.pre("updatedOne", function (next) {
this.options.runValidators = true;
next();
});
但他们都没有解决我的问题。我怎么办