CouchDB中的startkey和endkey如何工作? [英] How exactly is startkey and endkey working in CouchDB?

查看:170
本文介绍了CouchDB中的startkey和endkey如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CouchDB中的位置数据库。我创建了一个视图,其中的键是一个带有经度和纬度四舍五入值的数组。现在,我选择的条件如下:

I'm working with a locations database in CouchDB. I created a view where my key is an array with rounded values of latitude and longitude. Now I'm selecting with the following conditions:

Startkey: [ 52.34, 4.883 ]
Endkey:   [ 52.37, 4.903 ]

在这里,我希望我只会收到纬度在52.34和52.37之间的文档。经度介于4.883和4.903之间。

Here I expect that I'll only receive documents where the latitude is between 52.34 and 52.37. And the longitude between 4.883 and 4.903.

我收到的结果:

[ 52.358, 4.919 ]
[ 52.358, 4.919 ]
[ 52.362, 4.861 ]
[ 52.362, 4.861 ]
[ 52.362, 4.861 ]

您可能已经注意到,第一个结果是经度大于终止键的经度4.919。

As you may have noted, in the first result is the longitude greater then the longitude of the endkey, 4.919.

现在我知道/读到某个地方,我会收到一些超出数组第二项范围的值。但是,第一项可能已经不符合标准了吗?

Now I know/read somewhere that I would receive some values which are outside of range of the second item in the array. But how is it possible that the first item already doesn't fit the criteria?

我在Google周围搜索了一下,却找不到真正的startkey / endkey作为数组。谁能给我解释一下CouchDB如何遍历文档并定义何时开始和何时结束?

I Googled around a bit and I can't really find an explanation of the startkey/endkey as array. Who can give me a explanation of how CouchDB loops through the documents and defines when to 'start' and when to 'end'?

推荐答案

使用这些键在您的视图中假设以下数据:

assuming the following data in your view with these keys:

startkey == [a,11] endkey == [c,11]

[a, 10]
[a, 11]   <-- startkey
[a, 12]   <--
[b, 10]   <--
[b, 11]   <--
[b, 12]   <--
[c, 10]   <--
[c, 11]   <-- endkey
[c, 12]

(将返回带有箭头标记的所有内容)。

(Everything marked by an arrow will be returned).

使用键对视图中的数据进行排序。使用 startkey endkey ,您可以控制 start end 在视图中。您不能为数据指定约束。在 startkey endkey 之间排序的所有内容都将返回。有关更多信息,请阅读 http://wiki.apache.org/couchdb/View_collat​​ion

The data in the view are sorted using the key. With startkey and endkey you can control where to start and end in the view. You cannot specify constraints for the data. Everything that is sorted in between startkey and endkey will be returned. Please read http://wiki.apache.org/couchdb/View_collation for more information.

如果要进行地理空间查询,则应签出GeoCouch( https://github.com/couchbase/geocouch/ )。

If you want to do geospatial queries you should check out GeoCouch (https://github.com/couchbase/geocouch/).

总结:键在CouchDB中,视图存储在一维列表中。这些列表中的条目是根据 View_collat​​ion 中的规则进行排序的一个>。二维数组可能看起来很特殊,但实际上并非如此。 [a,10] 之后 [a] after a 之前 [b,5] 之前 [c] (例如)。

Summed up: Keys in CouchDB views are stored in one-dimensional lists. Entries in these lists are sorted according to the rules in View_collation. Two dimensional arrays may look special, but in fact they are not. [a, 10] is sorted after [a] and after a and before [b, 5] and before [c] (for example).

如果您使用 startkey endkey ,您说的是 startkey 之前和之后以及<$ c之前和之后的所有内容$ c> endkey 。 startkey endkey 条目不必 出现在列表中。

If you use startkey and endkey, you say "everything including and after startkey and before and including endkey". startkey and endkey entries do not have to be present in the list.

这篇关于CouchDB中的startkey和endkey如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆