Skip to content

Instantly share code, notes, and snippets.

@alexrutherford
Created October 8, 2015 17:31
Show Gist options
  • Select an option

  • Save alexrutherford/00bf93da79dbc3d17552 to your computer and use it in GitHub Desktop.

Select an option

Save alexrutherford/00bf93da79dbc3d17552 to your computer and use it in GitHub Desktop.
Count most common page categories in MongoDB
db.pages.aggregate([
{$match:{id:{$exists:true}}},
{$group:{_id:'$category',total:{$sum:1}}},
{$sort:{total:-1}}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment