Skip to content

Instantly share code, notes, and snippets.

@swinton
Created March 29, 2012 14:58
Show Gist options
  • Select an option

  • Save swinton/2238217 to your computer and use it in GitHub Desktop.

Select an option

Save swinton/2238217 to your computer and use it in GitHub Desktop.
MongoDB Map Reduce Example
var source = "STRESS";
var target = "stress_locations";
var map = function () {
if (this.tweet.user.location.trim()) {
emit(this.tweet.user.location, 1);
}
};
var reduce = function(key, values) {
return values.length;
};
db.tweets.mapReduce(map, reduce, {
out: {replace:target},
query: {$and:[{"SOURCE":source},{"tweet.user.location":{$exists:true}}]}
});
// db[target].find().forEach( printjson );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment