“用户验证失败:密码:需要路径‘密码’。” [关闭]
Posted
技术标签:
【中文标题】“用户验证失败:密码:需要路径‘密码’。” [关闭]【英文标题】:"user validation failed: passsword: Path `passsword` is required." [closed] 【发布时间】:2022-01-21 19:32:36 【问题描述】:这是我的猫鼬模型:
const mongoose=require('mongoose')
const userSchema=new mongoose.Schema(
firstName:
type:String,
required:true
,
middleName:
type:String,
,
lastName:
type:String,
required:true,
,
passsword:
type: String,
required: true,
,
email:
type:String,
unique:true,
sparse:true
,
phoneNumber:
type:Number
,
address:
permanentAddress:String,
temporaryAddress:[String]
,
gender:
type:String,
enum:['male','female','others']
,
dob:
type:Date
,
country:
type:String,
default:'Nepal'
,
image:
type:[String]
,
role:
type:Number,
default:2
,
isArchived:
type:Boolean,
default:false
,
status:
type:String,
enum:['active','inactive','frequent'],
default:'active'
,
passwordResetTOken:String,
passwordResetTokenExpiry:String
)
const userModel=mongoose.model('user',userSchema)
module.exports=userModel
控制器是:
function insert(data)
return new Promise(function(resolve,reject)
const newUser=new userModel
newUser.password = passwordHash.generate(data.password)
newUser.firstName=data.firstName
newUser.lastName=data.lastName
newUser.dob=data.dob
console.log("new user is",newUser.password)
console.log("mapped user is",newUser)
newUser.save(function(err,done)
if(err)
return reject(err)
console.log("user is",done)
resolve(done)
)
)
我收到错误:
"name": "ValidatorError",
"message": "Path `passsword` is required.",
但是req.body
有:
firstName: 'rajiv',
lastName: 'dahal',
password: 'admin',
dob: '2021/03/03'
我的错误是什么?
【问题讨论】:
【参考方案1】:您在定义用户架构时有一个错字。 password 属性的名称有 3 个 s
而不是 2 个。只需更新您的用户架构:
passs单词 -> pass单词
【讨论】:
【参考方案2】:应该是密码而不是密码
passsword:
type: String,
required: true,
,
【讨论】:
以上是关于“用户验证失败:密码:需要路径‘密码’。” [关闭]的主要内容,如果未能解决你的问题,请参考以下文章