NodeJS, Express, Mongoose and MongoDB RESTful Web Service – DELETE Request

Hey guys, in the previous post we discussed about updating the document with HTTP PATCH request. In this post, we will discuss about deleting document with HTTP DELETE request. let’s begin

In order to delete the document from mongodb, mongoose provides several methods like deleteOne(), findByIdAndDelete(), findOneAndDelete() and deleteMany(). so in this post, we will discuss about deleting document using findByIdAndDelete().

As the name suggests, we will pass a document id which we want to delete and this will return a Query object, on the query object we will call then().

Let’s look at an example..

router.delete('/blogs/:id', (req, res) => {
    Blog.findByIdAndDelete( => {
        if (!blog) {
            return res.status(404).send();
    }).catch((error) => {

using the req.params we will get the route parameter.

Let’s delete the second object



  • Id, document id which we want to delete
  • options, optional parameter
  • callbackfunction

It will return Queryobject

That’s all about this post, in the next post we will discuss about the other methods like deleteOne(), deleteMany() findOneAndDelete()

About the author

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *