【发布时间】:2016-04-11 11:09:33
【问题描述】:
我想在 CouchDB 中编写一个 MapReduce 函数,其中 Map 函数将键作为数组发出,但 reduce 函数仅使用映射键中的一个值。例如:
地图功能:
function(doc) {
if (doc.type_ === 'survey') {
emit([doc.timeRecorded_, doc.imei_], 1);
};
};
Reduce 函数:
function(k,v) {
// How to handle only the doc.imei_ as the value?
// Or, alternatively, how to filter based on timeRecorded_ somewhere other than the map function?
return sum(v)
}
timeRecorded_ 在 EPOCH 编号中,因此不会有重复(偶然除外)。如果我要对其进行汇总,则需要将其四舍五入为“天”值。或者,数据可以这样准备,即 timeRecorded_ 在源数据中已经四舍五入(可能更改为 dateRecorded_)
【问题讨论】: