Guest User

Untitled

a guest
Aug 7th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. // Get session
  2.  
  3. info := new(mgo.DialInfo)
  4. info.Username = "username"
  5. info.Password = "password"
  6. info.Source = "admin"
  7. info.Addrs = []string{"host"}
  8. info.Database = "dbname"
  9.  
  10. session, err := mgo.DialWithInfo(info)
  11. if err != nil {
  12. fmt.Printf("dial fail %v\n", err)
  13. os.Exit(1)
  14. }
  15. defer session.Close()
  16.  
  17. // Error check on every access
  18. session.SetSafe(&mgo.Safe{})
  19.  
  20. // Get collection
  21. collection := session.DB("dbname").C("collectionName")
  22.  
  23. // Delete record
  24. err = collection.Remove(bson.M{})
  25. if err != nil {
  26. fmt.Printf("remove fail %v\n", err)
  27. os.Exit(1)
  28. }
Add Comment
Please, Sign In to add comment