Map reduce on mongodb returns 递归结果
Map reduce on mongodb returns recursive result
我收集了一系列房地产,我 运行 在 mongodb 上进行 map reduce 以计算一些基本统计数据。在本地一切正常,但是当我在 mongohq 上执行 运行 任务时,我得到了递归结果。
让我稍微简化一下,而不是真正的 reduce fn,说 reduce 是:
function(key, values) {
return { values: values };
}
地图函数:
function() {
emit('price', this.price);
}
当我 运行 在本地执行任务时,输出如下:
{
"values": [
1024.1712707182319,
661.0377201728149,
651.5957446808511,
1553.7073816617014,
1128.664171911323
]
}
现在有趣的部分,当我 运行 它在生产数据库上时,输出如下:
{
"values": [
{
"values": [
{
"values": [
1561.5615615615618,
1026.2054507337525,
1428.5714285714287
]
},
1092.1177587844254,
1040.2010050251256,
1547.6190476190477
]
}
]
}
知道这里有什么问题吗?
罪魁祸首可能是您的 reduce
函数。
https://docs.mongodb.org/manual/reference/command/mapReduce/#dbcmd.mapReduce
the reduce function must be idempotent. Ensure that the following statement is true:
reduce( key, [ reduce(key, valuesArray) ] ) == reduce( key, valuesArray )
the reduce function should be commutative: that is, the order of the elements in the valuesArray should not affect the output of the reduce function, so that the following statement is true:
reduce( key, [ A, B ] ) == reduce( key, [ B, A ] )
希望这对您有所帮助,
我收集了一系列房地产,我 运行 在 mongodb 上进行 map reduce 以计算一些基本统计数据。在本地一切正常,但是当我在 mongohq 上执行 运行 任务时,我得到了递归结果。
让我稍微简化一下,而不是真正的 reduce fn,说 reduce 是:
function(key, values) {
return { values: values };
}
地图函数:
function() {
emit('price', this.price);
}
当我 运行 在本地执行任务时,输出如下:
{
"values": [
1024.1712707182319,
661.0377201728149,
651.5957446808511,
1553.7073816617014,
1128.664171911323
]
}
现在有趣的部分,当我 运行 它在生产数据库上时,输出如下:
{
"values": [
{
"values": [
{
"values": [
1561.5615615615618,
1026.2054507337525,
1428.5714285714287
]
},
1092.1177587844254,
1040.2010050251256,
1547.6190476190477
]
}
]
}
知道这里有什么问题吗?
罪魁祸首可能是您的 reduce
函数。
https://docs.mongodb.org/manual/reference/command/mapReduce/#dbcmd.mapReduce
the reduce function must be idempotent. Ensure that the following statement is true:
reduce( key, [ reduce(key, valuesArray) ] ) == reduce( key, valuesArray )
the reduce function should be commutative: that is, the order of the elements in the valuesArray should not affect the output of the reduce function, so that the following statement is true:
reduce( key, [ A, B ] ) == reduce( key, [ B, A ] )
希望这对您有所帮助,