Created
October 17, 2013 23:47
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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