0

Hi all im starting to work with couchdb im trying to rereduce this reduce function

function(key,values,rereduce){

 if(rereduce === true){

    //HELP HERE
    return results;
 } 


values.forEach(function(doc){

 if(results[(doc.id-1)]){
    results[(doc.id-1)].valori.push(doc.valore);
 }else{
    results[(doc.id-1)] = {
        id:doc.id,
        nome:doc.nome,
        unita:doc.unita,
        valori:[doc.valore]
    };  
 }
 });

return results;
}

someone can help me to rereduce this?

this is my Map output data

[2015, 7, 6, 0, 0, 26] ID: bfc53ce117b53ec023c528e0c3039fc7 {nome: "COT ist.INGRESSO ", valore: 309.6, id: 1, unita: "mg/Nm", ora: "00:00:26"} [2015, 7, 6, 0, 0, 26] ID: bfc53ce117b53ec023c528e0c303a032 {nome: "COT ist. USCITA ", valore: 5.4, id: 2, unita: "mg/Nm", ora: "00:00:26"} [2015, 7, 6, 0, 0, 26] ID: bfc53ce117b53ec023c528e0c303adf4 {nome: "Media TOC NIRA ", valore: 6.8, id: 3, unita: "mg/Nm", ora: "00:00:26"} [2015, 7, 6, 0, 0, 26] ID: bfc53ce117b53ec023c528e0c303b6a7 {nome: "Media TOC Giorn. ", valore: 7.3, id: 4, unita: "mg/Nm", ora: "00:00:26"} [2015, 7, 6, 0, 1, 26] ID: bfc53ce117b53ec023c528e0c303c3ee {nome: "COT ist.INGRESSO ", valore: 410.9, id: 1, unita: "mg/Nm", ora: "00:01:26"} [2015, 7, 6, 0, 1, 26] ID: bfc53ce117b53ec023c528e0c303c7e6 {nome: "COT ist. USCITA ", valore: 7, id: 2, unita: "mg/Nm", ora: "00:01:26"} [2015, 7, 6, 0, 1, 26] ID: bfc53ce117b53ec023c528e0c303cb60 {nome: "Media TOC NIRA ", valore: 6.4, id: 3, unita: "mg/Nm", ora: "00:01:26"} [2015, 7, 6, 0, 1, 26] ID: bfc53ce117b53ec023c528e0c303d729 {nome: "Media TOC Giorn. ", valore: 6.9, id: 4, unita: "mg/Nm", ora: "00:01:26"} [2015, 7, 6, 0, 2, 26] ID: bfc53ce117b53ec023c528e0c303df8e {nome: "COT ist.INGRESSO ", valore: 306.7, id: 1, unita: "mg/Nm", ora: "00:02:26"}

etc....

What i need after the reduce is:

[{nome:"COT ist.Ingresso", id:1, unita:"mg/Nm",valori:[309.6,5.4,.....]}
{name:"thename",id:2, unita:"mg/Nm",valori:[6.8,3.5,......]}...]

this is an array of 4 object (one each id) with valori field is the concat of the various valore field, ( ordered by key or ora property)

  • Please show a example of your data that should be reduced and your intention what reduce should do. Your function does not look like the common reduce functions.These mostly contain `if(rereduce){...}else{...}`. Check the documentation for further information: http://docs.couchdb.org/en/latest/couchapp/ddocs.html#reduce-and-rereduce-functions – h4cc Jul 05 '15 at 10:39
  • hi the map return this type of data an array of items like this [{ id:1, nome:"test", unita:"unitatest", valore:123},....] ( id go from 1 to 4 ) i need it reduced to an array of 4 objects like this [{ id:1, nome:"test", unita:"unitatest", data:[123,123,123]},{}..] (data is the concat array of all valore for the same id) – Samuele Coppedè Jul 05 '15 at 10:47
  • and the problem is the data lost the order – Samuele Coppedè Jul 05 '15 at 14:27
  • This is my map data output – Samuele Coppedè Jul 06 '15 at 09:05

0 Answers0