Created
September 17, 2014 08:54
-
-
Save dudarev/3315ceb427fe9ed3425b to your computer and use it in GitHub Desktop.
m101js.hw5.3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.grades.aggregate([ | |
{$unwind: '$scores'}, | |
{$match: | |
{"scores.type": {$in: ["exam", "homework"]}}}, | |
{$group: | |
{ | |
_id: { | |
'student_id': '$student_id', | |
'class_id': '$class_id' | |
}, | |
avg_score: {$avg: '$scores.score'} | |
} | |
}, | |
{$group: | |
{ | |
_id: { | |
'class_id': '$_id.class_id' | |
}, | |
avg_score: {$avg: '$avg_score'} | |
} | |
}, | |
{$sort: | |
{'avg_score': -1} | |
} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment