Skip to content

Instantly share code, notes, and snippets.

@trajano
Created May 5, 2013 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trajano/5520448 to your computer and use it in GitHub Desktop.
Save trajano/5520448 to your computer and use it in GitHub Desktop.
// drop and insert data
db.books.drop();
db.books.insert({
"title": "End to End Enterprise Architecture",
"authors": ["Archimedes Trajano"]
});
db.books.insert({
"title": "Deadpool: The Proper Screenplay",
"authors": ["Archimedes Trajano",
"Will Wheaton",
"Joseph Michael Straczynski"]
});
db.books.insert({
"title": "It's after January 19, 2038 at 3:15am",
"authors": [ "Archimedes Trajano",
"Will Wheaton",
"Sheldon Cooper" ]
});
// map-reduce
db.books.mapReduce(
function () {
print("Map: " + tojson(this));
emit(this.title, 42);
emit(this.title, 73);
},
function (key, values) {
print("Reduce: key=" + tojson(key) +
", values=" + tojson(values));
return 1;
},
{ "out": { "inline": 1 }}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment