请考虑以下存储在pouchdb中的示例文档。
{
"_id": "milk-20190509T010751.826-1",
"animal": "B",
"shift": "M",
"ltr": 5,
"code": 1,
"custName": "Balvant Jat",
"type": "milk",
"netAmt": 200,
"billName": "1951",
}
{
"_id": "milk-20190509T010751.827-1",
"animal": "B",
"shift": "M",
"ltr": 6,
"code": 1,
"custName": "Balvant Jat",
"type": "milk",
"netAmt": 150,
"billName": "1951",
}
{
"_id": "milk-20190509T010751.828-2",
"animal": "B",
"shift": "M",
"ltr": 6,
"code": 2,
"custName": "Ashvin Jat",
"type": "milk",
"netAmt": 500,
"billName": "1951",
}
我尝试了一些map / reduce函数,还使用了group:true
选项,但无法获得预期的结果。我尝试了如下的地图功能
mapFunc = (doc) => {
if(doc.type === 'milk'){
emit(doc.billName,{code:doc.code,name:doc.name,ltr:doc.ltr,amount:doc.netAmt})
}
}
但不知道我在哪里停下reduce函数。
我想成为如下所示的文档。
{
"code": 1,
"custName": "Balvant Jat",
"totalLtr": 11
"totalNetAmt": 350,
}
{
"code": 2,
"custName": "Ashvin Jat",
"totalLtr": 6
"totalNetAmt": 500,
}