Skip to content

Instantly share code, notes, and snippets.

@gurdotan
Created April 22, 2015 11:18
Show Gist options
  • Save gurdotan/b35600a7dcea167c12c8 to your computer and use it in GitHub Desktop.
Save gurdotan/b35600a7dcea167c12c8 to your computer and use it in GitHub Desktop.
MongoDB: most popular email domains
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