//(kitchen sink post för att testa syntaxhighlighter, dock blir detta än Join funktion om man moddar om lite)
(function recur(index, recursCallback) {
var keys = {};
keys[joinKey[1]] = sourceData[index][joinKey[0]];
otherData.findOne(keys, function(err, result) {
if(err)
return callback(err, result);
else
{
//Remove all fucking non-enumerable objects. (They are defining some getters and setters so you can assign the object in a normal way..)
//sourceData = JSON.parse(JSON.stringify(sourceData));
for(var key in result['_doc']) {
if(fields.indexOf(key) !== -1)
sourceData[index][key] = result[key];
}
if(++index < sourceData.length)
recur(index, recursCallback);
else {
recursCallback(sourceData);
}
}
});
})(0, function(out) {
callback(null, out);
});