Created
December 18, 2012 04:24
-
-
Save xseignard/4324997 to your computer and use it in GitHub Desktop.
Q2 from M101 final exam
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
// requires | |
var MongoClient = require('mongodb').MongoClient; | |
// mongodb uri | |
var uri = 'mongodb://localhost:27017/enron'; | |
MongoClient.connect(uri, function(err, db) { | |
console.log('Connecting to the db...'); | |
if (err) { | |
console.log('Error during connection. Aborting.'); | |
process.exit(1); | |
} | |
console.log('Connected'); | |
db.collection('messages', function(err,collection) { | |
collection.aggregate([ | |
{ $match: {'headers.From':{$in:['[email protected]','[email protected]','[email protected]','[email protected]']}}} | |
,{ $project: {'from':'$headers.From','to':'$headers.To'}} | |
,{ $unwind : '$to' } | |
,{ $group : { | |
_id: {from: '$from', to: '$to'}, | |
count: {$sum:1} | |
} | |
} | |
,{ $sort: {count:1}} | |
], | |
function(err, result) { | |
console.log(result); | |
db.close(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment