部署后在猫鼬模式中添加密码字符串长度验证

时间:2021-02-24 16:18:20

标签: node.js validation mongoose

这是我的名为 slate(在线调度程序)的待办事项列表的应用程序 https://murmuring-ravine-25508.herokuapp.com/。 我想在密码长度中添加验证。我通过写作修改了架构

const userschema = new mongoose.Schema ({

email:String,
    password:{
        type:String,
        minlength:5,
        maxlength:10
    }
}); 

但它什么也没做。 我不知道为什么架构没有更新。
我发现 {runValidators: true} 这是解决方案。但不知道在哪里添加它和它的完整代码。

1 个答案:

答案 0 :(得分:0)

你应该试试

const userschema = new mongoose.Schema ({

email:
{
type: String
},
    password:{
        type:String,
        minlength:5,
        maxlength:10,
       required: true
    }
});
相关问题