Skip to content

Instantly share code, notes, and snippets.

@visnup
Forked from gerad/top-domains.js
Created January 26, 2012 19:57
Show Gist options
  • Save visnup/1684734 to your computer and use it in GitHub Desktop.
Save visnup/1684734 to your computer and use it in GitHub Desktop.
query time spent by domain using tractor
var map = function() {
var domain = this.info.url.match(/^https?:\/\/([^\/]*)/)[1];
emit(domain, { duration: this.duration });
};
var reduce = function(key, values) {
var result = { duration: 0 };
values.forEach(function(value) {
result.duration += value.duration
});
return result;
};
db.items.mapReduce(map, reduce, {
query: { 'info.url': /^https?:\/\/([^\/]*)/ },
out: 'domain_durations' }
);
db.domain_durations.find().sort({ 'value.duration': -1 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment