Skip to content

Instantly share code, notes, and snippets.

@aliukevicius
Created January 10, 2016 15:57
Show Gist options
  • Save aliukevicius/7184933a2456d11a3e89 to your computer and use it in GitHub Desktop.
Save aliukevicius/7184933a2456d11a3e89 to your computer and use it in GitHub Desktop.
Golang mondoDB
package main
import (
"fmt"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
type Person struct {
Name string
Phone string
}
func main() {
session, _ := mgo.Dial("172.17.0.3")
defer session.Close()
session.SetMode(mgo.Monotonic, true)
c := session.DB("testdb").C("people")
_ = c.Insert(
&Person{"Alex", "+55 89 9556 9111"},
&Person{"John", "+55 98 8402 3256"})
result := Person{}
_ = c.Find(bson.M{"name": "Alex"}).One(&result)
fmt.Println("Phone:", result.Phone)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment