today my map function started reporting assertion failure 13076 ‘recursive toObject’ code. It worked just fine yesterday.
Here’s my map function:
function () {
for(i=0; i<this.values.length; i++) {
emit(this.values[i].id, {
'id': this.values[i].id,
'start_date': this.values[i].start_date,
'end_date': this.values[i].end_date,
'hash': this.values[i].hash,
'url': this.values[i].url});
}
}
I have tried replacing for loop with forEach function, but result is the same.
What is interesting function with scope variable limiting map function to single emit works just fine:
function () {
for(i=0; i<this.values.length; i++) {
if(this.values[i].id == myId) {
emit(this.values[i].id, {
'id': this.values[i].id,
'start_date': this.values[i].start_date,
'end_date': this.values[i].end_date,
'hash': this.values[i].hash,
'url': this.values[i].url});
}
}
}
I can, of course, perform this mapping directly in code, but I wouldn’t want to encounter this error some other time when I really need to use MapReduce.
Ok, so the error message was really vague, but the problem seems to be caused by duplicate value of the ‘id’ field in ‘values’ array. When I changed the id in one of the array elements the function started working again.