Whenever we want to clean up the database or delete the documents that are no longer needed, we can easily remove them using a MongoDB driver for Go (gopkg.in/mgo.v2), which we will be covering in this recipe.
Deleting your first document from MongoDB
How to do it...
- Install the gopkg.in/mgo.v2, gopkg.in/mgo.v2/bson, and github.com/gorilla/mux packages, using the go get command, as follows:
$ go get gopkg.in/mgo.v2
$ go get gopkg.in/mgo.v2/bson
$ go get github.com/gorilla/mux
- Create delete-record-mongodb.go. Then we connect to MongoDB, get the name of an employee to be deleted from the database as an HTTP request variable, get the named collection, and remove the document, as follows:
package main
import
(
"fmt"...