Database

[{"_id":NumberLong(1),"students":[1,2,3,4],"course":NumberLong(1),},{"_id":NumberLong(2),"students":[5,6,7,8,9,10,11],"course":NumberLong(1),},{"_id":NumberLong(3),"students":[12,13,14],"course":NumberLong(1),},{"_id":NumberLong(4),"course":NumberLong(1),}]

Query

db.collection.aggregate([{$project:{_id:0,students_count:{$size:{"$ifNull":["$students",[]]}},}},{$group:{_id:null,students_total:{$sum:"$students_count"},}}])

Result