I am developing a webapp in MERN stack, while doing so I encountered with an error , please help. When I try to update the user it gives me an error, Callback must be a function, got '[object Object]'.
This is the API.
It is guaranteed that user always exists.
module.exports.addBlog=(req,res)=>{
const {title,data} = req.body.blog;
console.log(title,data);
const {email} = req.body;
const newblog ={
title,
data
}
userSchema.findOneAndUpdate(
{email},
{$push:{blogArray:newblog}},
{upsert:true},
{useFindAndModify:false}
)
.then(res=>console.log(res))
.catch(err=>console.log(err));
return res.json({msg:"Blog added successfully"});
}
This is the userschema.
const userSchema = new mongoose.Schema({
firstname:{
type:String,
required:true,
lowercase:true
},
lastname:{
type:String,
required:true,
lowercase:true
},
email:{
type:String,
required:true,
lowercase:true
},
password:{
type:String,
required:true
},
blogArray:[
{
title:{
type:String,
required:true
},
data:{
type:String,
required:true
}
}
]
});