Created
February 8, 2015 12:34
-
-
Save oreillyross/5ae0079d71c80e1d700b to your computer and use it in GitHub Desktop.
H5.3 Mongo course. Aggregate and group function
This file contains hidden or 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': "homework"}}, | |
{$group: | |
{_id: {student_id: "$student_id", | |
class_id: "$class_id", | |
scorestype: "$scores.type", | |
}, | |
avg_scores: {$avg:"$scores.score"} | |
}}, | |
/* {$group: | |
{_id: {class: "$_id.class_id"}, | |
average: {$avg: "$avg_scores"}} | |
}, | |
{$sort: {'average': 1}} */ | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment