title: Can't get mongodb record by ObjectId in golang
body: <p>I'm try to get mongodb record by ObjectId by using following code, but keep getting <strong>not found</strong> by <code>err.Error()</code></p>
  
  <p>Following is my mongo collection sample </p>
  
  <pre><code>{ "_id" : ObjectId("5a2a75f777e864d018131a59"), "callDate" : "22/12/2017", "time" : "16.25", "callType" : "a", "position" : "aaa", "description" : "aaaaaa", "qty" : 2, "estimatedDuration" : 2.3, "estimatedOvertime" : 3.44, "rate" : 4, "laborExtension" : 3 }
  { "_id" : ObjectId("5a2a75f877e864d018131a5b"), "callDate" : "22/12/2017", "time" : "16.25", "callType" : "a", "position" : "aaa", "description" : "aaaaaa", "qty" : 2, "estimatedDuration" : 2.3, "estimatedOvertime" : 3.44, "rate" : 4, "laborExtension" : 3 }
  { "_id" : ObjectId("5a2a75fa77e864d018131a5d"), "callDate" : "22/12/2017", "time" : "16.25", "callType" : "a", "position" : "aaa", "description" : "aaaaaa", "qty" : 2, "estimatedDuration" : 2.3, "estimatedOvertime" : 3.44, "rate" : 4, "laborExtension" : 3 }
  </code></pre>
  
  <p>Following is my model</p>
  
  <pre><code>type RhinoJobs struct { 
  ID                bson.ObjectId  `db:"id" json:"id" bson:"_id"` 
  CallDate          string  `db:"call_date" json:"callDate" bson:"callDate"` 
  Time              string  `db:"time" json:"time" bson:"time"` 
  CallType          string  `db:"call_type" json:"callType" bson:"callType"` 
  Position          string  `db:"position" json:"position" bson:"position"` 
  Description       string  `db:"description" json:"description" bson:"description"` 
  Qty               int     `db:"qty" json:"qty" bson:"qty"` 
  EstimatedDuration float64 `db:"estimated_duration" json:"estimatedDuration" bson:"estimatedDuration"` 
  EstimatedOvertime float64 `db:"estimated_overtime" json:"estimatedOvertime" bson:"estimatedOvertime"` 
  Rate              float64 `db:"rate" json:"rate" bson:"rate"` 
  LaborExtension    float64 `db:"labor_extension" json:"laborExtension" bson:"laborExtension"` 
  } 
  </code></pre>
  
  <p>I want to get search these record by object id </p>
  
  <pre><code>"gopkg.in/mgo.v2"
  
  func GetMongoSession() (*mgo.Session, error) {
      if mgoSession == nil {
          var err error
          mgoSession, err = mgo.Dial(mongoConnectionUrl)
          if err != nil {
              return nil, err
          }
      }
      return mgoSession.Clone(), nil
  }
  
  
  
  func GetJobByID(objID string) (models.RhinoJobs, error) {
      var job models.RhinoJobs
      s, err := commons.GetMongoSession()
      if err != nil {
          errMsg := "error occurred while creating mongoDB connection stack:" + err.Error()
          print(err.Error())
          return job, errors.New(errMsg)
      }
      defer s.Close()
      err = s.DB("rhino").C("jobs").FindId(bson.ObjectIdHex("5a2a75f777e864d018131a59")).One(&amp;job)
      if err != nil {
          print(err.Error())
          errMsg := "error occurred while getting data :" + err.Error()
          return job, errors.New(errMsg)
      }
      return job, nil
  }
  </code></pre>
  
  <p>But when I try to get all collection records by following code it works fine  </p>
  
  <pre><code>err := s.DB("rhino").C("jobs").Find(nil).All(&amp;jobs)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/OOedf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/OOedf.png" alt="enter image description here"></a></p>
  
  <p>I also check following SO Q&amp;A but didn't work</p>
  
  <p><a href="https://stackoverflow.com/questions/26428281/querying-mongodb-from-golang-using-the-id-stored-in-an-array">Querying mongodb from golang using the _id stored in an array</a></p>
  
  <p><a href="https://stackoverflow.com/questions/35364816/how-to-find-by-id-in-golang-and-mongodb">How to find by id in golang and mongodb</a></p>
  
  <p><a href="https://stackoverflow.com/questions/20215510/cannot-retrieve-id-value-using-mgo-with-golang">Cannot retrieve &quot;_id&quot; value using mgo with golang</a></p>