Skip to content

Instantly share code, notes, and snippets.

@alexsandro-xpt
Created July 24, 2012 13:54
Show Gist options
  • Save alexsandro-xpt/3170014 to your computer and use it in GitHub Desktop.
Save alexsandro-xpt/3170014 to your computer and use it in GitHub Desktop.
Map Reduce, MongoDB
db.runCommand({
mapreduce: "Page",
map : function Map() {
emit(
this._id, // how to group
{"links":this.Links,"has":false} // associated data point (document)
);
},
reduce : function Reduce(key, values) {
var reduced = {"links":[],"has":false}; // initialize a doc (same format as emitted value)
for(var i=0,t=values.links.length;i<t;i++){
if(values.links[i].Hash=="5931305546993178356"){
reduced.has=true;
reduced.links.push(values.links[i]);
break;
}
}
return reduced;
},
finalize : function Finalize(key, reduced) {
return reduced.has;
},
query : { "value" : true },
out : { replace: "teste" , db: "teste" }
});
@alexsandro-xpt
Copy link
Author

Usando a seguinte estrutura de dados https://gist.github.com/3124417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment