title: group in mongo excluding null values
body: <p>I have mongo query which does the group operation on the documents.</p>
  
  <p>I have almost got the expected results except that I want to refine the results without empty or null values.</p>
  
  <p>Currently my query looks like this:</p>
  
  <pre><code>db.productMetadata.aggregate([{$group:{"_id":{"color":"$productAttribute.colour","gender":"$productAttribute.gender"},"count" : {$sum : 1}}}]);
  </code></pre>
  
  <p>And the results looks something like this:</p>
  
  <pre><code>{ "_id" : { "color" : "BLUE", "gender" : "MEN" }, "count" : 1 }
  { "_id" : {  }, "count" : 4 }
  { "_id" : { "color" : "NA", "gender" : "WOMEN" }, "count" : 1 }
  { "_id" : { "color" : "BLACK", "gender" : "MEN" }, "count" : 1 }
  { "_id" : { "color" : "BROWN", "gender" : "WOMEN" }, "count" : 1 }
  { "_id" : { "gender" : "MEN" }, "count" : 2 }
  { "_id" : { "color" : "BEIGE", "gender" : "MEN" }, "count" : 1 }
  { "_id" : { "color" : "BROWN", "gender" : "MEN" }, "count" : 1 }
  </code></pre>
  
  <p>I want to remove the rows if any of the group by field values are empty or null in the actual data of DB.</p>
  
  <p>Excepted results should look something like this:</p>
  
  <pre><code>{ "_id" : { "color" : "BLUE", "gender" : "MEN" }, "count" : 1 }
  { "_id" : { "color" : "NA", "gender" : "WOMEN" }, "count" : 1 }
  { "_id" : { "color" : "BLACK", "gender" : "MEN" }, "count" : 1 }
  { "_id" : { "color" : "BROWN", "gender" : "WOMEN" }, "count" : 1 }
  { "_id" : { "color" : "BEIGE", "gender" : "MEN" }, "count" : 1 }
  { "_id" : { "color" : "BROWN", "gender" : "MEN" }, "count" : 1 }
  </code></pre>