Created
March 7, 2015 13:39
-
-
Save iporsut/a727a0f7cfb8fbf751e8 to your computer and use it in GitHub Desktop.
Insert to MongoDB
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 ( | |
"log" | |
"gopkg.in/mgo.v2" | |
"gopkg.in/mgo.v2/bson" | |
) | |
func main() { | |
session, err := mgo.Dial("127.0.0.1:27017") | |
if err != nil { | |
log.Fatal(err) | |
return | |
} | |
defer session.Close() | |
collection := session.DB("test").C("Student") | |
err = collection.Insert(bson.M{"name": "Weerasak"}) | |
if err != nil { | |
log.Fatal(err) | |
return | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment