我使用CouchDb并想创建一个视图,用于计算文档中每个方的投票数。我什至无法显示所有参与者,在运行下面列出的功能后,它只会显示3个随机参与者。
我如何计算各方的票数?
CouchDB中的文档:
{
"_id": "729489bb6702c473bb72254d13003f85",
"_rev": "1-50da566becf84a0a686853290c2ad8a5",
"Projects": [
{
"city": "Kentucky",
"amount of people living": "853312",
"overview": [
{
"building": "Center building",
"amount of people": "150000",
"teams": [
{
"party": "xd",
"vote": "50"
},
{
"party": "zh",
"vote": "50"
},
{
"party": "gh",
"vote": "50"
},
{
"party": "sd",
"vote": "50"
}
]
},
{
"building": "Left building",
"amount of people": "120000",
"teams": [
{
"party": "gh",
"vote": "50"
},
{
"party": "sw",
"vote": "50"
},
{
"party": "gj",
"vote": "50"
}
]
},
{
"building": "Right building",
"amount of people": "200000",
"teams": [
{
"party": "sd",
"vote": "50"
},
{
"party": "gs",
"vote": "50"
},
{
"party": "er",
"vote": "50"
}
]
}
]
}
]
}
表2:
{
"_id": "729489bb6702c473bb72254d13003f85",
"_rev": "1-50da566becf84a0a686853290c2ad8a5",
"Projects": [
{
"city": "Kentucky",
"amount of people living": "853312",
"overview": [
{
"building": "Center building",
"amount of people": "150000",
"teams": [
{
"party": "xd",
"vote": "50"
},
{
"party": "zh",
"vote": "50"
},
{
"party": "gh",
"vote": "50"
},
{
"party": "sd",
"vote": "50"
}
]
},
{
"building": "Left building",
"amount of people": "120000",
"teams": [
{
"party": "xd",
"vote": "50"
},
{
"party": "zh",
"vote": "50"
},
{
"party": "gh",
"vote": "50"
}
]
},
{
"building": "Right building",
"amount of people": "200000",
"teams": [
{
"party": "xd",
"vote": "50"
},
{
"party": "zh",
"vote": "50"
},
{
"party": "gh",
"vote": "50"
}
]
}
]
}
]
}
我想要什么:
Key | Value
-----------------------------
xd | 300
zh | 300
gh | 300
sd | 100
我尝试使用但没有用的东西:
function (doc) {
var i;
for( i=0; i < doc.Projects.length; i++){
emit(doc.Projects[i].overview[i].teams[i].party,1);
}
}