Whenever you want to persist data in a MongoDB database, the first step you have to take is to establish a connection between the database and your web application, which we will be covering in this recipe using one of the most famous and commonly used MongoDB drivers for Go - gopkg.in/mgo.v2.
Integrating MongoDB and Go
Getting ready...
Verify whether MongoDB is installed and running locally on port 27017 by executing the following command:
$ mongo
This should return the following response:
![](https://static.packt-cdn.com/products/9781787286740/graphics/assets/063c04f9-4a03-455a-b1f7-723eba8828e7.png)
How to do it...
- Install the gopkg.in/mgo.v package, using the go get command...