title: How to ignore nulls while unmarshalling a MongoDB document?
body: <p>I would like to know if there's any approach that would allow me to ignore null types while unmarshalling a MongoDB document into a Go struct.</p>
  
  <p>Right now I have some auto-generate Go structs, something like this:</p>
  
  <pre class="lang-golang prettyprint-override"><code>type User struct {
    Name  string `bson:"name"`
    Email string `bson:"email"`
  }
  </code></pre>
  
  <p>Changing the types declared in this struct is not an option, and here's the problem; in a MongoDB database, which I do not have total control, some of the documents have been inserted with null values were originally I was not expecting nulls. Something like this:</p>
  
  <pre><code>{
    "name": "John Doe",
    "email": null
  }
  </code></pre>
  
  <p>As the string types declared inside my struct are not pointers, they can't receive a <code>nil</code> value, so whenever I try to unmarshall this document in my struct, it returns an error.</p>
  
  <p>Preventing the insertion of this kind of document into the database would be the ideal solution, but for my use case, ignoring the null values would also be acceptable. So after unmarshalling the document my User instance would look like this</p>
  
  <pre class="lang-golang prettyprint-override"><code>User {
    Name:  "John Doe",
    Email: "",
  }
  </code></pre>
  
  <p>I'm trying to find, either some annotation flag, or an option that could be passed to the method <code>Find</code>/<code>FindOne</code>, or maybe even a query parameter to prevent returning any field containing null values from the database. Without any success until now.</p>
  
  <p>Are there any built-in solutions in the mongo-go-driver for this problem?</p>