Skip to content

Instantly share code, notes, and snippets.

@pietrom
Created September 21, 2015 06:53
Show Gist options
  • Save pietrom/b3440795dec08a2e0bca to your computer and use it in GitHub Desktop.
Save pietrom/b3440795dec08a2e0bca to your computer and use it in GitHub Desktop.
db.messages.aggregate([
{ $unwind: '$headers.To' },
{ $group: { _id: { id: '$_id', from: '$headers.From'}, to: { $addToSet: '$headers.To' }}},
{ $unwind: '$to' },
{ $group: { _id: { from: '$_id.from', to: '$to'}, hits: {$sum: 1}}},
{ $match: { hits: {$gt: 1} } },
{ $sort: { hits: -1 }}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment