Created
April 22, 2015 11:18
-
-
Save gurdotan/b35600a7dcea167c12c8 to your computer and use it in GitHub Desktop.
MongoDB: most popular email domains
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
var emails = {}; | |
db.users.find().sort({_id: -1}).forEach(function(d) { | |
var email = d.email.split('@')[1]; | |
emails[email] |= 0; | |
emails[email]++; | |
}); | |
var sortable = []; | |
for (var email in emails) | |
sortable.push([email, emails[email]]) | |
sortable.sort(function(a, b) {return b[1] - a[1]}) | |
printjson(sortable); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment