Skip to content

Instantly share code, notes, and snippets.

@jeffyuhaoliu
Created October 17, 2013 23:47
Show Gist options
  • Save jeffyuhaoliu/7034301 to your computer and use it in GitHub Desktop.
Save jeffyuhaoliu/7034301 to your computer and use it in GitHub Desktop.
MongoDB & Node.js Final 2 - Please use the Enron dataset you imported for the previous problem. For this question you will use the aggregation framework to figure out pairs of people that tend to communicate a lot. To do this, you will need to unwind the To list for each message. This problem is a little tricky because a recipient may appear mor…
use enron
db.messages.aggregate([
{
$unwind: "$headers.To"
},
{
$project: {
"_id": 1,
"headers.From": 1,
"headers.To": 1
}
},
{
$group: {
_id: { id: "$_id", from: "$headers.From", to: "$headers.To" },
count: { $sum: 1 }
}
},
{
$group: {
_id: { from: "$_id.from", to: "$_id.to" },
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