couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benoit Chesneau" <bchesn...@gmail.com>
Subject bug in grouped reduce ?
Date Fri, 20 Jun 2008 23:09:20 GMT
Hi all,

I have someting weird with  grouped reduce :

I get value [row1, row2, ..., rown ]  which is correct, but from time
to time I get :
[ [row1, row2, ..., rown ]] . any idee why ? Is this a bug in my
function or in couchdb ?

The reduce function is :

function (key, values) {
  var idx_comments = {};
  var comments = [];
  for (var i=0; i<values.length; i++) {
    if (values[i]) {
        idx_comments[values[i]['_id']] = values[i];
        if (!values[i]['parent'])
              comments.push(values[i]);
    }
  }

   function iter_comments(lcomments) {
     for (var i=0; i<lcomments.length; i++) {
       var comment = lcomments[i] || [];
       var thread=[];
       if (comment['children'] && comment['children'].length > 0) {
         for (var j=0; j<comment['children'].length; j++) {
            thread.push(idx_comments[comment['children'][j]]);
         }
         if (thread && thread.length >0) {
           comment['thread'] = iter_comments(thread);
         } else {
           comment['thread'] = null;
         }
        }

        lcomments[i] = comment;

      }
      return lcomments;
    }
    tmp = iter_comments(comments);
    return tmp;
}


regards,

- benoƮt

Mime
View raw message