I have a map reduce function that works on a collection as follows:
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;
}
What I am trying to do is that the Finalize will only return objects that pass a certain threshold (e.g. count>10). Currently it is still returning objects and the count is just null.
Any ideas?