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..

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

Let’s delete the second object

Model.findByIdAndDelete()


Parameters:

  • 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

Well, I am Bushan Sirgur from Banglore, India. Currently, I am working as a Software Developer in a Service Base Company. I am interested in JAVA/J2EE, Angular 2, JavaScript, jQuery, MongoDB.

View all posts

Leave a Reply

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