'Trying to use findByIdAndUpdate but the error Cannot read properties of undefined (reading 'id') keeps showing

error: Cannot read properties of undefined (reading 'id') findByIdAndRemove works fine only findByIdAndUpdate show errors

app.post('/update',(res,req)=>{
User.findByIdAndUpdate(req.body.id,{
    fname:req.body.fname,
    lname:req.body.lname,
    email:req.body.email,
    password:req.body.password
})
.then(data=>{
    console.log(data)
    res.send("updated")
}).catch(err=>{
    console.log(err)
})

})

app.post('/delete',(req,res)=>{
User.findByIdAndRemove(req.body.id)
.then(data=>{
    console.log(data)
    res.send("deleted")
}).catch(err=>{
    console.log(err)
})

})



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source