You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
574 B

  1. package main
  2. import (
  3. mgo "gopkg.in/mgo.v2"
  4. )
  5. func getSession() (*mgo.Session, error) {
  6. session, err := mgo.Dial("mongodb://" + config.Mongodb.IP)
  7. if err != nil {
  8. panic(err)
  9. }
  10. //defer session.Close()
  11. // Optional. Switch the session to a monotonic behavior.
  12. session.SetMode(mgo.Monotonic, true)
  13. // Optional. Switch the session to a monotonic behavior.
  14. session.SetMode(mgo.Monotonic, true)
  15. return session, err
  16. }
  17. func getCollection(session *mgo.Session, collection string) *mgo.Collection {
  18. c := session.DB(config.Mongodb.Database).C(collection)
  19. return c
  20. }