I have data collection which has different students with diff marks,I want to count how many students got certain numbers of 100,90,80,70,60 etc marks and if no student has that specific mark, I want that resulting output as 0
Eg: ,
{ $group: { "_id": studentMarks, "studentMarksTotal": { $sum: 1 } } },
{ $sort: { _id: 1 } },
{
$project: {
_id: 0,
studentMarksTotal: 1,
studentMarks:{
$cond: { if: { $eq: ["$_id", "$studentMarks"] }, then: "$_id", else: "0" },
,
},
}}
]
this gives the result for values that have count Eg: studentMarks:70, studentMarksTotal:9 studentMarks:90, studentMarksTotal:6
but I also want count data if no student got certain marks
eg:studentMarks:70, studentMarksTotal:9 studentMarks:90, studentMarksTotal:6 studentMarks:100, studentMarksTotal:0
How can I achieve not, I have tried $ifNull and if else also but am unable to get the desired result
If anyone could help me with this, Thanks in advance.