I'm trying to run pagerank using mapreduce in mongodb.
My documents are in this format:
{
"_id" : "u: 10000",
"value" : [
[
"u: 10000",
"s: 985272",
1
],
[
"s: 985272",
"u: 10000",
1
],
[
"u: 10000",
"s: 303770",
1
],
[
"s: 303770",
"u: 10000",
1
]
]
}
Now I think the first step is to collect the links by key. However I have several outbound links per document. (These all happen to be bidirectional).
Here are my map and reduce functions:
m = function () {
for (var i = 0; i < this.value.length; i++){
var out = {};
out.out = this.value[i][1];
out.weight = this.value[i][2];
emit(this.value[i][0], [out]);
}
}
r = function(key, values){
var result = {
value: []
};
values.forEach(function(val) {
result.value.push({out: val.out, weight: val.weight});
});
return result;
}
The problem is I'm not sure that emit is producing multiple emissions per document. As I get results like:
{
"_id" : "s: 1000082",
"value" : [
{
"out" : "u: 37317",
"weight" : 1
}
]
}
When I would expect multiple items per document.
Anyone have any ideas? Help would be appreciated!
EDIT:
I'm not completely satisfied, for example how do things like this work?. The reduce result doesn't at all look like the emit output.