Skip to content

Instantly share code, notes, and snippets.

@h2rd
Created December 3, 2012 11:39
Show Gist options
  • Select an option

  • Save h2rd/4194415 to your computer and use it in GitHub Desktop.

Select an option

Save h2rd/4194415 to your computer and use it in GitHub Desktop.
Mongo get grader class in the campus
use test
db.grades.aggregate([
{ $unwind: "$scores" }
, { $group: {
_id: {
type: "$scores.type"
, score: "$scores.score"
, class_id: "$class_id"
}
}
}
, { $match: {
'_id.type': { $ne: 'quiz' }
}
}
, { $group: {
_id: "$_id.class_id"
, avg: { $avg: "$_id.score"}
}
}
, { $sort: { avg: -1 } }
, { $limit: 1}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment