我有一个适用于集合的 map reduce 函数,如下所示:
function Map() {
emit (
this.name,
{
count : 1,
flag : this.flag
}
);
}
function Reduce(key, values) {
var count = 0;
var flag = false;
for (var i in values){
count = count + 1;
if (i.flag)
flag = true;
}
var reduced = {
count : count,
flag : flag
}
return reduced;
}
function Finalize(key, reduced) {
if (reduced.count>10 || reduced.flag){
var finalized = {
"count" : reduced.count
}
return reduced;
}
return null;
}
我想要做的是 Finalize 只会返回通过某个阈值(例如 count>10)的对象。目前它仍在返回对象,计数为空。
有任何想法吗?