我在couchdb http://guide.couchdb.org/draft/cookbook.html#unique上关注此指南,以便从视图中返回distinct
列表。
我的地图功能如下:
function(doc) {
if(doc.PartnerName !=null) {
emit(doc.PartnerName, null);
}
}
并且,我有一个reduce函数:
function(keys, values) {
return true;
}
当我按下命令运行时:
/ DBNAME / _design /合作伙伴/ _view /我的 - 视图 - 名称
我得到了回复:
{"rows":[
{"key":null,"value":true}
]}
如果我将?reduce=false
添加到最后,我会回复排序所需的结果:
{
"total_rows":11,"offset":0,
"rows":[
{"id":"a","key":"PARTNER_ONE","value":null},
{"id":"b","key":"PARTNER_ONE","value":null},
{"id":"c","key":"PARTNER_ONE","value":null},
{"id":"d","key":"PARTNER_ONE","value":null},
{"id":"e","key":"PARTNER_ONE","value":null},
{"id":"f","key":"PARTNER_ONE","value":null},
{"id":"g","key":"PARTNER_TWO","value":null},
{"id":"h","key":"PARTNER_TWO","value":null},
{"id":"i","key":"PARTNER_TWO","value":null},
{"id":"j","key":"PARTNER_THREE","value":null},
{"id":"k","key":"PARTNER_FOUR","value":null}
]}
但是,我理想地想要获得一个独特的列表,所以在上面的例子中,它是PARTNER_ONE,PARTNER_TWO,PARTNER_THREE,PARTNER_FOUR
答案 0 :(得分:1)
我认为你错过了group=true
参数。尝试查询
/dbName/_design/Partners/_view/my-view-name?group=true
并查看是否能为您提供正确的结果。