This is a creation in Article, where the information may have evolved or changed.
Golang mongodb MgO Insert, query a small example, Golang still give me that feeling, than Nodejs write up comfortable. Package main import ("FMT" "Launchpad.net/mgo" "Launchpad.net/mgo/bson") type Mail struct {Id Bson. ObjectId "_id" Name string Email String} func Main () {//Connect to database session, err: = MgO. Dial ("127.0.0.1") if err! = Nil {panic (ERR)} defer session. Close ()//Gets the database, gets the collection c: = Session. DB ("Test"). C ("Mail")//Store data m1: = Mail{bson. Newobjectid (), "User1", "user1@dotcoo.com"} m2: = Mail{bson. Newobjectid (), "User1", "user2@dotcoo.com"} m3: = Mail{bson. Newobjectid (), "User3", "User3@dotcoo.com"} M4: = Mail{bson. Newobjectid (), "User3", "user4@dotcoo.com"} err = C.insert (&m1, &m2, &M3, &M4) if err! = Nil { Panic (ERR)}//Read data ms: = []mail{} err = C.find (&bson. m{"name": "User3"}). All (&MS) if err! = Nil {panic (ERR)}//Display data for I, M: = Range ms {FMt. Printf ("%s,%d,%s\n", M.id.hex (), I, M.email)}}