I have a simple User model with a property called bio as follows:
const userSchema = new mongoose.Schema{
bio:{
type: String,
max: 150,
default: "Welcome to my linktree!"
}
}
I have a function to edit bio as follows:
exports.editBio = async (req, res) => {
User.findByIdAndUpdate({_id: req.user._id}, {bio: req.body}, (err,data) => {
if(err){
res.json(err)
}else{
res.json(`Bio updated`)
}
})
}
However, I keep getting the error:
{
"stringValue": "\"bio\"",
"valueType": "string",
"kind": "ObjectId",
"value": "bio",
"path": "_id",
"reason": {},
"name": "CastError",
"message": "Cast to ObjectId failed for value \"bio\" (type string) at path \"_id\" for model \"User\""
}
How can I fix this?