Use findByIdAndUpdate to Change Documents
- receives regular Javascript object as its parameter
- optional
{ new: true }
parameter cause event handler to be called with new modified document
blogsRouter.put('/:id', async (request, response) => { const blog = request.body const updatedBlog = await Blog.findByIdAndUpdate(request.params.id, blog, { new: true }) response.json(updatedBlog)})
Source -> Mongoose: findByIdAndUpdate method
To fix the deprecated warnings we need to add following to schema definition module
mongoose.set('useFindAndModify', false)
Source -> Stack Overflow