Guest User

Untitled

a guest
Jan 3rd, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "log"
  5. "time"
  6.  
  7. "github.com/globalsign/mgo"
  8. "github.com/globalsign/mgo/bson"
  9. )
  10.  
  11. func main() {
  12.  
  13. var pruebas []bson.D
  14.  
  15. c := NewConnection()
  16. err := c.Find(nil).All(&pruebas)
  17.  
  18. if err != nil {
  19. log.Fatal(err)
  20. }
  21.  
  22. log.Println(pruebas)
  23.  
  24. }
  25.  
  26. func NewConnection() *mgo.Collection {
  27.  
  28. info := &mgo.DialInfo{
  29. Addrs: []string{"localhost:27017"},
  30. Timeout: 10 * time.Second,
  31. Username: "oneloop",
  32. Password: "oneloop360",
  33. }
  34.  
  35. session, err := mgo.DialWithInfo(info)
  36.  
  37. if err != nil {
  38. panic(err)
  39. }
  40.  
  41. session.SetMode(mgo.Monotonic, true)
  42.  
  43. collection := session.DB("prueba").C("prueba")
  44.  
  45. return collection
  46. }
Add Comment
Please, Sign In to add comment