Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Get session
- info := new(mgo.DialInfo)
- info.Username = "username"
- info.Password = "password"
- info.Source = "admin"
- info.Addrs = []string{"host"}
- info.Database = "dbname"
- session, err := mgo.DialWithInfo(info)
- if err != nil {
- fmt.Printf("dial fail %v\n", err)
- os.Exit(1)
- }
- defer session.Close()
- // Error check on every access
- session.SetSafe(&mgo.Safe{})
- // Get collection
- collection := session.DB("dbname").C("collectionName")
- // Delete record
- err = collection.Remove(bson.M{})
- if err != nil {
- fmt.Printf("remove fail %v\n", err)
- os.Exit(1)
- }
Add Comment
Please, Sign In to add comment