Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save h2rd/4194282 to your computer and use it in GitHub Desktop.
Get top author from array in mongo
use blog
db.posts.aggregate([
{ $unwind: "$comments" }
, { $group: {
_id: "$comments.author"
, total: {$sum: 1}
}
}
, { $sort: { total: -1 } }
, { $limit: 1}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment