Skip to main content

how to solve Cast to ObjectId failed for value

    <form action="" method="post"> 
    <input type="password" name="password" placeholder="Enter 
    Your Password" required>
    <input type="hidden" name="user_id" value="<%=user_id%> ">
    <br><br>
    <input type="submit" value="Reset Password">
    </form>"

// routes 
user_route.post('/forget-password', userController.resetPassword);

//controllers
const resetPassword = async(req,res)=>{
try {
    const user_id = req.body.user_id;
    const password = req.body.password;

    const secure_password = await securePassword(password);

    const updatedData  = await User.findByIdAndUpdate({ _id:user_id }, { $set:{ password:secure_password, token:""}});

         res.redirect("/");

} catch (error) {
    console.log(error.message)
}

} Output Server is connected at port 3000 Connection Succesful Email has been sent:- 250 2.0.0 OK 1661801316 i2- 20020a170902c94200b00174f7d107c8sm1521208pla.293 - gsmtp Cast to ObjectId failed for value "{ _id: '630ce985474a211c98fe80c2 ' }" (type Object) at path "_id" for model "User"

Via Active questions tagged javascript - Stack Overflow https://ift.tt/Z7KLNyP

Comments