优艾设计网

怎样在couchdb里面有js让 key加上lable name,比如UserId: " 财富值88?

优艾设计网 https://www.uibq.com 2023-04-25 12:10 出处:网络 作者:磨皮美容教程
请教下怎样写javascript,在couchdb里面,把key加上lable nameUserId:\"abc123\", couchdb里面有个list 功能不知可否实现,谢谢以下是已经有的map reduce和list功能map function(doc) { var usersLength = doc.users

请教下怎样写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 }.... ]}


0

精彩评论

暂无评论...
验证码 换一张
取 消