title: Count number of fields have data in a collection with aggregate mongodb
body: <p>This is my collections with sample database:</p>
  
  <pre><code>{ 
      "_id" : ObjectId("5a9797b480591678e0771190"), 
      "staff_id" : NumberInt(172), 
      "temp_name" : "Regular Employment", 
      "individual_setting" : false, 
      "employment_category" : "Regular Employee", 
      "branch_office" : "Cebu Branch Office", 
      "availability_status" : "Incumbent", 
      "req_working_hours" : "08:00", 
      "fixed_brk_time_from" : "12:00", 
      "fixed_brk_time_to" : "13:00", 
      "sch_time_setting" : [
          {
              "holiday" : [
                  "Saturday", 
                  "Friday"
              ], 
              "biweekly_odd" : [
  
              ], 
              "biweekly_even" : [
                  "Saturday"
              ], 
              "clock_in_mon" : "08:40", 
              "clock_in_tue" : "08:40", 
              "clock_in_wed" : "08:40", 
              "clock_in_thu" : "08:40", 
              "clock_in_fri" : "08:40", 
              "clock_in_sat" : "08:40", 
              "clock_in_sun" : null, 
              "clock_in_hol" : null, 
              "clock_out_mon" : "18:00", 
              "clock_out_tue" : "18:00", 
              "clock_out_wed" : "18:00", 
              "clock_out_thu" : "18:00", 
              "clock_out_fri" : "18:00", 
              "clock_out_sat" : "18:00", 
              "clock_out_sun" : null, 
              "clock_out_hol" : null, 
              "_id" : ObjectId("5a9797b480591678e077118f")
          }
      ], 
      "date_to_start" : ISODate("2018-03-01T06:03:32.050+0000"), 
      "createdAt" : ISODate("2018-03-01T06:03:32.066+0000"), 
      "updatedAt" : ISODate("2018-03-01T06:03:32.066+0000"), 
      "__v" : NumberInt(0)
  }
  </code></pre>
  
  <p>Between the field <code>clock_in_mon</code> to <code>clock_in_hol</code> under <code>sch_time_setting</code> field, I want to count how many fields that have data or is not null. Because each staff has different time_setting, so those fields might have few data in other staff.</p>
  
  <p>The expected count for this is: 6, because only <code>clock_in_mon</code> to <code>clock_in_sat</code> have data.</p>
  
  <p>I tried code from here <a href="https://stackoverflow.com/questions/13811379/count-fields-in-a-mongodb-collection">Count fields in a MongoDB Collection</a> but I can't make it in my case.</p>