Created
January 10, 2016 15:57
-
-
Save aliukevicius/7184933a2456d11a3e89 to your computer and use it in GitHub Desktop.
Golang mondoDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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