mongodb - Aggregate counting logical values -


hello friend not friendly mongodb aggregation want have array of object contains subjects score each question , using node js want full calculation mongo query if possible include subject name total score , count of attempt , not attempt json array bellow

{     "examid": objectid("597367af7d8d3219d88c4341"),     "questionid": objectid("597368207d8d3219d88c4342"),     "questionno": 1,     "subject": "reasoning ability",     "yourchoice": "a",     "correctmark": "1",     "attempt": true,     "notattempt": false, } 

here in object 1 field correct marks subject different want output

|subject name | total attempts | total not attempts | total score | |           | 5              | 3                  | 10          | | b           | 10             | 5                  | 25          | 

i trying aggregation not done yet have tried query

db.examscores.aggregate([   { $group:{     _id:"$examid",     score: { $sum: '$correctmark' },     count: { $sum: 1 }   }} ]) 

any 1 has idea how achieve type of output. , if way achieve using node good.

i have solved here query

[  { $match: { subject:'reasoning ability' } },  {    $group:      {        _id:{id:"$examid",subject:'$subject'},        totalattempt: { $sum:  {$cond : [ "$attempt", 1, 0 ]} },        totalnotattempt: { $sum:  {$cond : [ "$notattempt", 1, 0 ]} },        markedforreview:{ $sum:  {$cond : [ "$markedforreview", 1, 0 ]} },        answerandmarkedforreview:{ $sum:  {$cond : [ "$answerandmarkedforreview", 1, 0 ]} },        score: { $sum: '$correctmark' },        count: { $sum: 1 }      }  } 

]


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -