• 2022-05-29
    以下不能实现统计各个部门男教师的人数的命令是?
    A: db.teachers.aggregate([{$match:{"sex":"男"}},{$group:{"_id":{"dept":"$dept"},"num_count":{$sum:1}}}])
    B: db.teachers.aggregate([{$group:{"_id":{"dept":"$dept"},"num_count":{$sum:1}}},{$match:{"sex":"男"}}])
    C: db.teachers.group({"key":{"dept":2},"initial":{"count":0},"reduce":function(cur,result){return result.count++},"cond":{"sex":"男"}})
    D: db.teachers.runCommand({"group":{"ns":"teachers","key":{"dept":0},"initial":{"count":0},"$reduce": function(cur,result){result.count++;},"cond":{"sex":"男"}}})
  • 举一反三