Skip to content

Instantly share code, notes, and snippets.

@olisikh
Created December 13, 2012 10:20
Show Gist options
  • Save olisikh/4275510 to your computer and use it in GitHub Desktop.
Save olisikh/4275510 to your computer and use it in GitHub Desktop.
Mongodb aggregation framework query (pairs of people that tend to communicate a lot)
use enron;
db.messages.aggregate([
{ $unwind: '$headers.To' },
{ $project: { _id: 0, 'headers.To': 1, 'headers.From': 1 } },
{ $group: { _id: { to: '$headers.To', from: '$headers.From' }, count: { $sum : 1 } } },
{ $sort: { count: -1 } },
{ $limit: 5 }
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment