【发布时间】:2018-03-01 06:10:43
【问题描述】:
这是我收集的示例数据库:
{
"_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)
}
在clock_in_mon 字段sch_time_setting 字段下的clock_in_hol 之间,我想计算有多少字段有数据或不为空。因为每个员工都有不同的time_setting,所以这些字段在其他员工中可能很少有数据。
预期的计数是:6,因为只有 clock_in_mon 到 clock_in_sat 有数据。
我尝试了Count fields in a MongoDB Collection 这里的代码,但我无法做到。
【问题讨论】:
-
显示您当前的尝试
标签: mongodb count field aggregate