title: In MongoDB, how to remove a field with a certain value in all documents that have it?
body: <p>I have a collection named <em>employees</em></p>
  <p>I want to remove all fields that have a null value in all documents inside the <em>employees</em> collection.</p>
  <p>This is my code in creating the database:</p>
  <pre><code>db.employees.insertMany( [ {&quot;Name&quot;: &quot;Stephen Jackson&quot;, &quot;Salary&quot;: 16099.55, &quot;Position&quot;: &quot;President&quot;, 
  &quot;Rank&quot;: 1, &quot;ReportingTo&quot;: null} ] )
  
  db.employees.insertMany( [ {&quot;Name&quot;: &quot;Michael Harrison&quot;, &quot;Salary&quot;: 14567.12, &quot;Position&quot;: &quot;Vice- 
  President&quot;, &quot;Rank&quot;: 2, &quot;ReportingTo&quot;: &quot;[President]&quot;} ] )
  
  db.employees.insertMany( [ {&quot;Name&quot;: &quot;Rex Andres&quot;, &quot;Salary&quot;: 13891.22, &quot;Position&quot;: &quot;Secretary&quot;, 
  &quot;Rank&quot;: 3, &quot;ReportingTo&quot;: &quot;[Vice-President]&quot;} ] )
  
  db.employees.insertMany( [ {&quot;Name&quot;: &quot;Sam Johnson&quot;, &quot;Salary&quot;: 13000, &quot;Position&quot;: &quot;Treasurer&quot;, &quot;Rank&quot;: 
  4, &quot;ReportingTo&quot;: &quot;[Secretary, Vice-President]&quot;} ] )
  </code></pre>
  <p>Here is what I tried doing:</p>
  <pre><code>db.employees.update( {&quot;ReoportingTo&quot;: null}, {&quot;$unset&quot;: {&quot;ReportingTo&quot;: &quot;&quot;}} )
  </code></pre>
  <p>I was expecting the field in the first document to be removed since it's the only one with the null value.</p>