title: Best practice to maintain a mgo session
body: <p>I'm currently using a mongodb with mgo lib for a web application, but I'm not sure if the way I'm using it, is good one ..</p>
  
  <pre><code>package db
  
  import (
      "gopkg.in/mgo.v2"
  )
  
  const (
      MongoServerAddr = "192.168.0.104"
      RedisServerAddr = "192.168.0.104"
  )
  
  var (
      MongoSession, err = mgo.Dial(MongoServerAddr)
  
      MDB  = MongoSession.DB("message")
      MCol = MDB.C("new")
      MSav = MDB.C("save")
  
      UDB  = MongoSession.DB("account")
      UCol = UDB.C("user")
  )
  </code></pre>
  
  <p>I init the db session and create variables who takes the collection and document value,
  so when I need to query a collection, I use the variable to make it.</p>
  
  <p>Like that :</p>
  
  <pre><code>func UserExist(username string) bool {
      user := Users{}
      err := db.UCol.Find(bson.M{"username": username}).One(&amp;user)
      if err != nil {
          return false
      } else {
          return true
      }
  }
  </code></pre>
  
  <p>So is there a best practice or this one is fine ..?
  Thanks</p>