我在两个集合上运行mapreduce。当我在我的机器上的单个实例上运行它时,它工作正常,但是当我在分片群集上运行它时,它给出了我的错误,如下图所示:
两个集合都拥有大约10K的文档,文档足够小,只有7-8个字段。
有人可以帮我解决这个问题,为什么我在分片环境中而不是简单的实例中获得此异常。
更新 地图&减少功能如下:
var mapF1 = function(){
var output = {};
var dataToHash = '';
this.hashCode = function(data) {
var hash = 0, i, chr, len;
if (data.length == 0) return hash;
for (i = 0, len = data.length; i < len; i++) {
chr = data.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
for(var record in this.Value){
output = {};
dataToHash = '';
for(var column in this.Value[record]){
var returnData = '';
if (Date.parse(this.Value[record][column]) && this.Value[record][column].length >= 8) {
var tempDate = new Date(this.Value[record][column]);
returnData += tempDate.getDate() + '-' +tempDate.getMonth()+'-'+tempDate.getFullYear();
dataToHash += returnData;
}else if(isNumber(this.Value[record][column])){
dataToHash += (this.Value[record][column] + '').split('.')[0];
} else {
dataToHash += this.Value[record][column];
}
output[column] = this.Value[record][column];
}
output.hashcolumn = this.hashCode(dataToHash);
emit(output.hashcolumn + '_S', output);
};
};
var mapF2 = function(){
var output = {};
var dataToHash = '';
this.hashCode = function(data) {
var hash = 0, i, chr, len;
if (data.length == 0) return hash;
for (i = 0, len = data.length; i < len; i++) {
chr = data.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
for(var record in this.Value){
output = {};
dataToHash = '';
for(var column in this.Value[record]){
var returnData = '';
if (Date.parse(this.Value[record][column]) && this.Value[record][column].length >= 8) {
var tempDate = new Date(this.Value[record][column]);
returnData += tempDate.getDate() + '-' +tempDate.getMonth()+'-'+tempDate.getFullYear();
dataToHash += returnData;
}else if(isNumber(this.Value[record][column])){
dataToHash += (this.Value[record][column] + '').split('.')[0];
} else {
dataToHash += this.Value[record][column];
}
output[column] = this.Value[record][column];
}
output.hashcolumn = this.hashCode(dataToHash);
emit(output.hashcolumn + '_T', output);
};
};
var reduceF = function(key, values) {
return values[0];
};
db.runCommand(
{
mapReduce: 'source',
map: mapF1,
reduce: reduceF,
out: { merge: 'map_reduce_results', db: 'mydb' }
}
)
db.runCommand(
{
mapReduce: 'target',
map: mapF2,
reduce: reduceF,
out: { merge: 'map_reduce_results', db: 'mydb' }
}
)
输出存储在名为 map_reduce_results
的集合中