简体   繁体   English

在Couchdb中订购

[英]Order by in Couchdb

I have a couch database that contains a name and a country field and i have created a view that returns a count per country. 我有一个包含名称和国家/地区字段的沙发数据库,​​并且创建了一个返回每个国家/地区计数的视图。

Map function: 地图功能:

function(doc) {
   emit(doc.country, 1);
}

Reduce function: 缩小功能:

function(keys, values, rereduce) {
   return sum(values);
}

The problem is that i need to make an "order by", in this case by the count, descending. 问题是我需要做一个“ order by”,在这种情况下是按计数递减。 Any idea how to solve it? 知道如何解决吗?

Unfortunately, with vanilla couchdb, you can't sort the value on the reduce function. 不幸的是,使用香草长沙发,您无法对reduce函数的值进行排序。

Cloudant, a couchdb hosted provider, offers "chained map reduce" which solves this problem. 长沙发数据库托管提供商Cloudant提供了“链式地图缩减”解决了此问题。 See http://examples.cloudant.com/sales/_design/sales/index.html 请参阅http://examples.cloudant.com/sales/_design/sales/index.html

You could do a couple options, one is host your data on cloudant, or two replicate your local data to cloudant to query your order-by. 您可以选择两种方法,一种是将数据托管在cloudant上,或者两种将本地数据复制到cloudant来查询订购依据。

There is also this: https://github.com/afters/couch-incarnate which unfortunately I have not tried, but might fit for what you are trying to do. 还有这个: https : //github.com/afters/couch-incarnate ,不幸的是我没有尝试过,但是可能适合您尝试做的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM