title: Best way to validate for bsonnull in a bson document in C#
body: <p>My sample document looks like this.</p>
  
  <pre><code> sampledoc = { "name" : "shan",
                     "address" : {
                                  "add1" : "",
                                  "add2": null
                                  }
                    }
  </code></pre>
  
  <p>if i need to get the value of add2 = > </p>
  
  <pre><code>var valueR = sampledoc["address"].asbsondocument["add2"].asstring;
  </code></pre>
  
  <p>So if value is there it is giving perfect.
  If address is bsonNull in mongodb , that time it is giving cast error.</p>
  
  <p>So i m using condition like </p>
  
  <pre><code>if(!sampledoc["address"].IsBsonNUll &amp;&amp; !sampledoc["address"].asbsondocument["add2"].IsBsonNUll )
  {
  //do that stuff
  }
  </code></pre>
  
  <p>this is fine.
  but if the nested document is upto 3-4 level then these look's bad.</p>
  
  <p>Is there any other way to validate as whole like that <strong>add2 field is null or not in a line as straight without validating like i did in that IF Condition separetly</strong> ?</p>