Skip to content

Instantly share code, notes, and snippets.

@nfrankel
Last active December 18, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nfrankel/5780044 to your computer and use it in GitHub Desktop.
Save nfrankel/5780044 to your computer and use it in GitHub Desktop.
MongoDB aggregation framework example
db.grades.aggregate([
{$unwind: "$aaa"},
{$match: {$or: [{"aaa.bbb": "gloubi"}, {"aaa.bbb": "boulga"}]}},
{$group: { _id: {ccc: "$ccc_id", ddd: "$ddd_id"}, avg: {$avg: "$aaa.eee"}}},
{$group: {_id: "$_id.ccc", avg: {$avg: "$fff"}}},
{$sort: {ggg : -1}},
{$limit: 1}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment