Created
April 29, 2015 19:54
-
-
Save fbiville/9e1f999d1d484aabc521 to your computer and use it in GitHub Desktop.
Exam Mongo
This file contains hidden or 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
| var recipient = "[email protected]"; | |
| db.messages.aggregate([ | |
| { | |
| "$match": { | |
| "headers.From": "[email protected]" | |
| } | |
| }, | |
| { | |
| "$unwind": "$headers.To" | |
| }, | |
| { | |
| "$match": { | |
| "$or": [ | |
| {"headers.To": recipient}, | |
| {"headers.Bcc": {"$regex":".*" + recipient + ".*"}}, | |
| {"headers.Cc": {"$regex":".*" + recipient + ".*"}} | |
| ] | |
| } | |
| }, | |
| { | |
| "$group": { | |
| _id: null, | |
| count: { $sum: 1 } | |
| } | |
| } | |
| ]) | |
This file contains hidden or 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
| 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