Hi,

This morning I hit reduce limit while trying to recreate a tree from
documents containing a "parent" member. I tried first to create an
index of documents and add to value a children member :

function(keys, values, rereduce) {

  var idx_comments = {};
  if(!rereduce) {
    for (var i in values) {
      value = values[i];
      children = [];
      if (idx_comments[value['_id']] != undefined)
        children = idx_comments[value['_id']]['children'];
      value['children'] = children
      idx_comments[value._id] = value;

      if (value['parentid']) {
        if (idx_comments[value['parentid']] == undefined)
          idx_comments[value['parentid']] = {};
        if (idx_comments[value['parentid']]['children']  == undefined)
          idx_comments[value['parentid']]['children'] = [];
        idx_comments[value['parentid']]['children'].push(value._id);
      }
    }
  } else {
    return values;
  }

But I wonder if it's the right way to do it, since reduce will be
calculated each time in this case. For now I go back on client side
but it may be better I guess.

- benoƮt

  return idx_comments;
}

Reply via email to