title: Mongodb C# driver ignore Null and Empty Lists (ToBsonDocument)
body: <pre class="lang-cs prettyprint-override"><code>ConventionRegistry.Register(&quot;IgnoreIfDefault&quot;, 
                              new ConventionPack { new IgnoreIfDefaultConvention(true) }, 
                              _ =&gt; true);
  
  var bsonDocument = anon.ToBsonDocument();
  </code></pre>
  <p>using IgnoreIfDefaultConvention can cause an unintended behavior due to the fact it affects all default values. For instance, values, as listed below, will not be saved:</p>
  <pre class="lang-cs prettyprint-override"><code>int = 0
  decimal = 0
  bool = false
  </code></pre>
  <p>If I want to ignore only <strong>null values and Empty Arrays</strong> what is the best approach?</p>