大家好我即将开始使用couchdb 我试图重新减少这种减少功能
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;
}
有人可以帮我减少这个吗?
这是我的地图输出数据
[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"}
等...
减少后我需要的是:
[{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,......]}...]
这是一个4对象的数组(每个id一个),valori字段是各种valore字段的concat,(按键或ora属性排序)