This is a created article in which the information may have evolved or changed.
About MgO
MongoDB officials do not have the drive to go MongoDB, so only use third-party drivers, MgO is the most used one.
MgO (sound mango) is a go language driver for MongoDB, which is rich in features and is well tested with a simple API based on GO syntax.
Official website: Http://labix.org/mgo
Installation and use
Installation
go get gopkg.in/mgo.v2
Use in Go
package modelsimport ("gopkg.in/mgo.v2""log")type Person struct {Name stringPhone string}const URL = "127.0.0.1:27017"func AddPerson() string {session, err := mgo.Dial(URL) //连接数据库if err != nil {log.Fatal(err)}defer session.Close()session.SetMode(mgo.Monotonic, true)db := session.DB("mydb")collection := db.C("person")err = collection.Insert(&Person{"Ale", "+55 53 8116 9639"}, &Person{"Cla", "+55 53 8402 8510"})if err != nil {log.Fatal(err)}return "true"}
See red Elephant ued for more information