Skip to content

Instantly share code, notes, and snippets.

@gerad
Created January 26, 2012 19:07
Show Gist options
  • Save gerad/1684424 to your computer and use it in GitHub Desktop.
Save gerad/1684424 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: { app: 'Safari', '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