We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: PostMessage.findByIdAndRemove is not a function
server/controllers/post.js - deletePost() export const deletePost = async (req, res) => { const { id } = req.params; if (!mongoose.Types.ObjectId.isValid(id)) return res.status(404).send(`No post with id: ${id}`); await PostMessage.findByIdAndRemove(id); **<== Error Source ===>** res.json({ message: "Post deleted successfully." }); }
Cause: As of Mongoose version 8 there is no more .findByIdAndRemove() in its place you will have to use .findByIdAndDelete() Model.findByIdAndDelete()
Fix: use findByIdAndDelete()
export const deletePost = async (req, res) => { const { id } = req.params; if (!mongoose.Types.ObjectId.isValid(id)) return res.status(404).send(`No post with id: ${id}`); await PostMessage.findByIdAndDelete(id); **<== Fix ===>** res.json({ message: "Post deleted successfully." }); }
The text was updated successfully, but these errors were encountered:
fix: Fix issue adrianhajdin#182
ae06078
I've create a pull request #184 addressing this change 😄
Sorry, something went wrong.
No branches or pull requests
TypeError: PostMessage.findByIdAndRemove is not a function
Cause:
As of Mongoose version 8 there is no more .findByIdAndRemove() in its place you will have to use .findByIdAndDelete()
Model.findByIdAndDelete()
Fix: use findByIdAndDelete()
The text was updated successfully, but these errors were encountered: