在 couchdb 中如何使用 reduce _count 对值进行排序
In couchdb How to get sorting on value with reduce _count
"myview": {
"map": "function(doc) { if (doc.type == 'user') emit(doc.city,null)}",
"reduce": "_count"
},
它 return 具有计数值的城市。使用组=真
如何根据最高值对这个数据库进行排序?想先得到最热门的城市...
您可以使用列表对结果集进行排序。以下函数可以根据值对任何类型的结果集进行排序。
"sort": "function() {
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}))
}"
"myview": {
"map": "function(doc) { if (doc.type == 'user') emit(doc.city,null)}",
"reduce": "_count"
},
它 return 具有计数值的城市。使用组=真
如何根据最高值对这个数据库进行排序?想先得到最热门的城市...
您可以使用列表对结果集进行排序。以下函数可以根据值对任何类型的结果集进行排序。
"sort": "function() {
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}))
}"