我已经使用CouchDB创建了一个联系人应用程序用于联系人存储。您可以在下面找到文档的示例。我正在尝试使用MapReduce函数返回联系人的名字以及有多少个联系人具有该名字。
示例文档:
Doc 1:
{
"_id": "2b0c6d587b0bce12f510c2400a003add",
"_rev": "1-3cfdc3f185ea42c0672b7960667ed3e4",
"firstName": "Alan",
"lastName": "O' Sullivan",
"number": {
"home": "0662837462",
"mobile": "0872817263"
},
"email": "alan.osullivan@gmail.com"
}
文档2:
{
"_id": "2b0c6d587b0bce12f510c2400a003add",
"_rev": "1-3cfdc3f185ea42c0672b7960667ed3e4",
"firstName": "Alan",
"lastName": "O' Sullivan",
"number": {
"home": "0662837462",
"mobile": "0872817263"
},
"email": "alan.osullivan@gmail.com"
}
文档3:
{
"_id": "2b0c6d587b0bce12f510c2400a003add",
"_rev": "1-3cfdc3f185ea42c0672b7960667ed3e4",
"firstName": "Timmy",
"lastName": "Bobby",
"number": {
"home": "0662837462",
"mobile": "0872817263"
},
"email": "timmy.bobby@gmail.com"
}
基于以上这些文档,我希望MapReduce函数返回的示例为:
{"rows":[
{"key":"Alan","value":2}
{"key":"Timmy","value":1}
]}
Alan的值为2,因为有两个名字为Alan的联系人。 Timmy的值是1,因为有一个名字叫Timmy的联系人。