title: Get value of pointer of a struct field using reflect
body: <pre><code>package main
  
  import (
      &quot;fmt&quot;
      &quot;reflect&quot;
  )
  
  type PetDetails struct {
      Name *string
  }
  
  type Student struct {
      Fname  string
      Lname  string
      City   string
      Mobile *int
      Pet *PetDetails
  }
  
  func main() {
      i := 7777777777
      petName := &quot;Groot&quot;
      s := Student{&quot;Chetan&quot;, &quot;Tulsyan&quot;, &quot;Bangalore&quot;, &amp;i, &amp;PetDetails{&amp;petName}}
      v := reflect.ValueOf(s)
      typeOfS := v.Type()
      
      for i := 0; i&lt; v.NumField(); i++ {
          fmt.Printf(&quot;Field: %s\tValue: %v\n&quot;, typeOfS.Field(i).Name, v.Field(i).Interface())
      }
  }
  </code></pre>
  <p>I am trying to convert these struct into map[string]string as I need the map for update query of mongoDB. After converting my struct to BSON, instead of querying { &quot;pet.name&quot;: &quot;Groot&quot; } it becomes { &quot;pet&quot;: { &quot;name&quot;: &quot;Groot&quot; } } which deletes other fields inside the embedded document pet. I'm not sure how to override BSON marshals as I'm using mongodb driver, not mgo</p>
  <p>I would like to get value of Mobile pointer and Name of the Pet, but all I get is the address</p>
  <p>How can I get the value, e.g. 7777 and Groot ? Thanks</p>