Skip to content

Instantly share code, notes, and snippets.

@mdirolf
Created April 1, 2010 18:26
Show Gist options
  • Save mdirolf/352187 to your computer and use it in GitHub Desktop.
Save mdirolf/352187 to your computer and use it in GitHub Desktop.
db.test.drop();
db.test.save({authors: ["mike"]});
db.test.save({authors: ["mike", "eliot"]});
db.test.save({authors: ["eliot", "dwight", "steve", "mike"]});
db.test.save({authors: ["steve", "mike"]});
var res = db.test.mapReduce(
function() {
var that=this;
that.authors.forEach(function(a){
that.authors.forEach(function(b){
if(a !== b){
var doc = {};
doc[a] = b;
emit(doc, 1);
};
});
});
},
function(k, vals) {
var sum=0;
for(var i in vals) sum += vals[i];
return sum;
});
db[res.result].find().forEach(
function(doc) {
printjson(doc);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment