title: How use update function of mongo-go-driver using struct
body: <p>The update function of mongo-go-driver can be called like this.</p>
  
  <pre class="lang-golang prettyprint-override"><code>filter := bson.D{"username", username}
  update := bson.D{{"$set",
      bson.D{
          {"name", person.Name},
      },
  }}
  result, err := collection.UpdateOne(ctx, filter, update)
  </code></pre>
  
  <pre class="lang-golang prettyprint-override"><code>type Person struct {
      ID       primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
      Username string             `json:"username,omitempty" bson:"username,omitempty"`
      Name     string             `json:"name,omitempty" bson:"name,omitempty"`
  }
  </code></pre>
  
  <p>But, I need to call the update function using the <code>person</code> struct, without mentioning every field of person struct like this.</p>
  
  <pre class="lang-golang prettyprint-override"><code>filter := bson.D{"username", username}
  update := bson.D{{"$set", &lt;&lt;how to convert person struct to bson document?&gt;&gt;}}
  result, err := collection.UpdateOne(ctx, filter, update)
  </code></pre>
  
  <p>How can I convert the person struct to bson document?</p>