Skip to content

Instantly share code, notes, and snippets.

@lnmunhoz
Last active December 20, 2015 12:08
Show Gist options
  • Save lnmunhoz/6128222 to your computer and use it in GitHub Desktop.
Save lnmunhoz/6128222 to your computer and use it in GitHub Desktop.
Final Exam M101P Q2.
use enron
db.messages.aggregate([
{'$project' : {'_id' : '$_id' , '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'}, 'emails' : {'$sum' : 1}}},
{'$sort' : {'emails' : -1}},
{'$limit' : 5}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment