Skip to content

Instantly share code, notes, and snippets.

@fbiville
Created April 29, 2015 19:54
Show Gist options
  • Save fbiville/9e1f999d1d484aabc521 to your computer and use it in GitHub Desktop.
Save fbiville/9e1f999d1d484aabc521 to your computer and use it in GitHub Desktop.
Exam Mongo
var recipient = "jeff.skilling@enron.com";
db.messages.aggregate([
{
"$match": {
"headers.From": "andrew.fastow@enron.com"
}
},
{
"$unwind": "$headers.To"
},
{
"$match": {
"$or": [
{"headers.To": recipient},
{"headers.Bcc": {"$regex":".*" + recipient + ".*"}},
{"headers.Cc": {"$regex":".*" + recipient + ".*"}}
]
}
},
{
"$group": {
_id: null,
count: { $sum: 1 }
}
}
])
db.messages.aggregate([
{"$project": {"to":"$headers.To", "from":"$headers.From"}},
{"$unwind": "$to"},
{"$group": {"_id":"$_id", "from": {"$first": "$from"},"to": {"$addToSet": "$to"}}},
{"$unwind": "$to"},
{"$group": {"_id": {"from":"$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