Once a BSON document is created we may need to update some of its fields. In that case, we have to execute update/upsert queries on the MongoDB collection, which we will be covering in this recipe.
Updating your first document in 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 update-record-mongodb.go. Then we connect to the MongoDB database, update the name of an employee for an ID, and write the number of records updated in MongoDB to an HTTP response stream, as follows:
package main
import
(
"fmt"
"log"
...