Created
July 24, 2012 13:54
-
-
Save alexsandro-xpt/3170014 to your computer and use it in GitHub Desktop.
Map Reduce, MongoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usando a seguinte estrutura de dados https://gist.github.com/3124417