Couchbase 视图:按键排序
Couchbase View : Sorting on Keys
我正在使用 Couchbase 3.0,并且我有一个我想执行排序的用例,但是当我通过 couchbase 时,它不提供对值的排序,但它提供对键的排序,但是当我使用 descending(true)它返回给我空列表。另一方面,如果我只是简单地使用它而不下降那么它会给我所有相关的文档。
我的地图功能是:
function (doc, meta) {
emit([meta.id,doc.latest.sortData],null);
}
}
现在我的用例是我想在 meta.id 上执行匹配查询,然后对所有匹配的案例对数据进行排序,然后找出最高值。
我使用的代码是:
ViewQuery.from(DesignDocName, viewName).startKey(JsonArray.from(write(List("something","")))).descending(true).limit(5).stale(Stale.FALSE))
如果我删除降序参数,那么我会得到相关的行,但它们没有排序。那么能否请您提供一种方法来完成此操作。
感谢任何帮助
谢谢!
我在阅读 Couchbase 的文档时偶然发现了这一行:
Because selection is made after sorting the view results, if you
configure the results to be sorted in descending order and you are
selecting information using a key range, then you must also reverse
the startkey and endkey parameters.
看这里:http://docs.couchbase.com/admin/admin/Views/views-querying.html#ordering
我正在使用 Couchbase 3.0,并且我有一个我想执行排序的用例,但是当我通过 couchbase 时,它不提供对值的排序,但它提供对键的排序,但是当我使用 descending(true)它返回给我空列表。另一方面,如果我只是简单地使用它而不下降那么它会给我所有相关的文档。
我的地图功能是:
function (doc, meta) {
emit([meta.id,doc.latest.sortData],null);
}
}
现在我的用例是我想在 meta.id 上执行匹配查询,然后对所有匹配的案例对数据进行排序,然后找出最高值。
我使用的代码是:
ViewQuery.from(DesignDocName, viewName).startKey(JsonArray.from(write(List("something","")))).descending(true).limit(5).stale(Stale.FALSE))
如果我删除降序参数,那么我会得到相关的行,但它们没有排序。那么能否请您提供一种方法来完成此操作。
感谢任何帮助
谢谢!
我在阅读 Couchbase 的文档时偶然发现了这一行:
Because selection is made after sorting the view results, if you configure the results to be sorted in descending order and you are selecting information using a key range, then you must also reverse the startkey and endkey parameters.
看这里:http://docs.couchbase.com/admin/admin/Views/views-querying.html#ordering