Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created August 13, 2011 16:02
Show Gist options
  • Save JakubOboza/1143985 to your computer and use it in GitHub Desktop.
Save JakubOboza/1143985 to your computer and use it in GitHub Desktop.
MongoDB Sample MapReduce in a file with usage
#!/bin/bash
mongo localhost:27017/data_gatherer test.js
var map = function(){
emit(this.url, 1);
}
var reduce = function(key, values){
var res = 0;
values.forEach(function(v){ res += 1});
return {count: res};
}
db.sites.mapReduce(map, reduce, { out: "mapped_urls" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment