CouchDB Map/Reduce raises execption in reduce function?
- by fuzzy lollipop
my view generates keys in this format
["job_id:1234567890", 1271430291000]
where the first key element is a unique key and the second is a timestamp in milliseconds. I run my view with this elapsed_time?startkey=["123"]&endkey=["123",{}]&group=true&group_level=1
and here is my reduce function, the intention is to reduce the output to get the earliest and latest timestamps and return the difference between them and now
function(keys,values,rereduce)
{
var now = new Date().valueOf();
var first = Number.MIN_VALUE;
var last = Number.MAX_VALUE;
if (rereduce)
{
first = Math.max(first,values[0].first);
last = Math.min(last,values[0].last);
}
else
{
first = keys[0][0][1];
last = keys[keys.length-1][0][1];
}
return {first:now - first, last:now - last};
}
and when processing a query it constantly raises the following execption:
function raised exception (new TypeError("keys has no properties", "", 1))
I am making sure not to reference keys inside my rereduce block. Why does this function constantly raise this exception?