1

I was trying to create view collations following this tutorial: http://elegantcode.com/2012/02/14/view-collation-in-couchdb/ but I realize that the result was an array with 5 elements with 2 objects types instead of an array with 2 items and those items with another array. Am I supposed to organize this array when I receive the result? Or is there another way of doing relationships on couchdb?

2

Ok, I found the solution, I have to use the reduce function for that, like:

function(keys, values, rereduce){
var result = null; 
var orders = []
for(var i =0; i< values.length; i++){
if(values[i].type=='customer') result = values[i];
    else{
          orders.push(values[i])

    }
}
result.orders = orders;

return result;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.