"user validation failed: passsword: Path `passsword` is required."



这是我的Mongoose模型:

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'
}

我犯了什么错?

您在定义用户模式时有一个拼写错误。对于密码属性的名称,您有3个s而不是2。只需更新您的用户架构:

passs单词->pass单词

应该是密码而不是密码

passsword:{
type: String,
required: true,
},

相关内容

  • 没有找到相关文章

最新更新