有没有办法设置猫鼬来检查两个值是否在单个模式中匹配?
Is there a way to set up mongoose to check if two values match in a single schema?
我是 node.js 的新手,需要进行一些基本验证以检查两个字段(在本例中为密码)是否匹配,如果不匹配,则显示错误消息。我现在不担心加密,因为它超出了范围,因为这是 uni 任务的最后一部分。
我试过创建可以传递给另一个变量的变量,但没有太大帮助。
这是我所拥有内容的简短片段。
架构:
const customerSchema = new mongoose.Schema(
{
password:
{
type: String,
required: true,
},
rePassword:
{
type: String,
required: true,
},
已发布
app.post("/", function(req,res)
{
let newCustomer = Customer(
{
password: req.body.cPass,
rePassword: req.body.cConfPass,
感谢任何帮助:)
已解决!
原来我需要在 运行 函数之前做这件事,它看起来像
if(req.body.cPass != req.body.cConfPass)
{
console.log("passwords don't match")
}
else
{
newCustomer.save();
}
我是 node.js 的新手,需要进行一些基本验证以检查两个字段(在本例中为密码)是否匹配,如果不匹配,则显示错误消息。我现在不担心加密,因为它超出了范围,因为这是 uni 任务的最后一部分。
我试过创建可以传递给另一个变量的变量,但没有太大帮助。
这是我所拥有内容的简短片段。
架构:
const customerSchema = new mongoose.Schema(
{
password:
{
type: String,
required: true,
},
rePassword:
{
type: String,
required: true,
},
已发布
app.post("/", function(req,res)
{
let newCustomer = Customer(
{
password: req.body.cPass,
rePassword: req.body.cConfPass,
感谢任何帮助:)
已解决!
原来我需要在 运行 函数之前做这件事,它看起来像
if(req.body.cPass != req.body.cConfPass)
{
console.log("passwords don't match")
}
else
{
newCustomer.save();
}