Here is my Mongoose model:
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
The controller is:
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)
})
})
}
I am getting error:
"name": "ValidatorError",
"message": "Path `passsword` is required.",
But req.body
has:
{
firstName: 'rajiv',
lastName: 'dahal',
password: 'admin',
dob: '2021/03/03'
}
What is my mistake?