请教下怎样写javascript,在couchdb里面,把key加上lable nameUserId:"abc123", couchdb里面有个list 功能不知可否实现,谢谢
以下是已经有的map reduce和list功能
map
function(doc) { var usersLength = doc.users.length; for (var i = 0; i < usersLength ; i++) { if (doc.users[i].UserId) {emit([doc.users[i].UserId,doc.Service.type,doc.Service.counTry], 1); } }}
reduce:
function(keys, values, rereduce) { return sum(values); }
list:
function(head, req){var row;var rows=[];while(row = getRow()){ rows.push(row); } rows.sort( function(a, b){return a.value - b.value; }); rows.reverse();send(JSON.stringify({"rows" : rows}))}
然后访问view优艾设计网_设计百科:_list/orderList/labelforkey?startkey=["abc123"]&endkey=["abc123",{}]&group=true
目前得到的结果是:
{ "rows": [ { "key": [ "abc123", "HardWare", "US", ], "value": 134 }.... ][ { "key": [ "abc123", "HardWare", "CA", ], "value": 120 }.... ]}
如何给key加上lable, 比如UserId:"abc123",如下所示:
{ "rows": [ { "key": [ UserId:"abc123", Service.type:"HardWare", Service.counTry:"US", ], "value": 134 }.... ]}
精彩评论