Skip to content

Instantly share code, notes, and snippets.

@pvoznenko
Created September 25, 2014 06:29
f2
db.messages.aggregate([
{$project: {from:"$headers.From", to:"$headers.To"}},
{$unwind:"$to"},
{$group: { _id:{_id: "$_id", from: "$from"}, to: {$addToSet:"$to"} }},
{$unwind:"$to"},
{$group: { _id: {from:"$_id.from", to:"$to"}, count: {$sum:1}}},
{$sort:{count:-1}}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment