How it works...

Once we run the program, the HTTP server will start locally listening on port 8080.

Next, executing a DELETE request to delete a BSON document from the command line as follows will give you the name of the document deleted from the database:

$ curl -X DELETE http://localhost:8080/employee/delete?name\=barDocument with name bar is deleted from database

Let’s look at the program we have written:

  1. We defined a deleteDocument handler, which gets the name to be deleted from MongoDB as the request variable, gets the employee collection from MongoDB, and calls the collection.Remove handler to remove a document for a given name.
  2. Then, we registered a deleteDocument handler to be called for the URL pattern /employee/delete for every ...

Get Go Web Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.