简体   繁体   English

CouchDB有多个约束

[英]CouchDB multiple constraints

I have a set of documents in CouchDB that are geolocalized - that is, they have a structure like 我在CouchDB中有一组地理定位的文档 - 也就是说,它们具有类似的结构

{
  _id: ...,
  ...
  coords: {
    lat: 45.204149214,
    long: 40.284712972
  }
}

I want to be able to display them on a map. 我希望能够在地图上显示它们。 This requires me to get all documents in a given square. 这要求我在给定的方格中获取所有文档。 It is easy to get all documents with longitude in a given interval: 在给定的时间间隔内很容易获得经度的所有文档:

// map function
function(doc) {
  emit(doc.coords.long, doc.other_stuff);
}

using a query like 使用类似的查询

// query
/path/to/view/?startkey=40&endkey=50

The problem is that I do not see how to do multidimensional constraints. 问题是我没有看到如何做多维约束。 How to get all documents with latitude between, say, 20 and 30 and longitude between 40 and 50? 如何获得纬度介于20 30之间,经度介于40到50之间的所有文档? I see I can specify multiple keys, but that will or the results. 我看到我可以指定多个键,但那会结果。

One option would be to do further filtering on the client, but given the size of the data, this may be unfeasible. 一种选择是在客户端上进行进一步过滤,但考虑到数据的大小,这可能是不可行的。

Disclaimer : there are a few similar questions on SO, basically stating that this is not possible. 免责声明 :在SO上有一些类似的问题,基本上说明这是不可能的。 Since they all look dated, I would like to know whether something has changed in the latest releases of CouchDB. 由于它们看起来都过时了,我想知道最新版本的CouchDB中是否有变化。

You are correct, you cannot do multidimensional queries. 你是对的,不能做多维查询。 But there is GeoCouch . 但是有GeoCouch It pretty easy to add to couch db through build-couchdb , or you can use iriscouch hosting which has it baked in by default. 通过build-couchdb添加到沙发数据库很容易,或者您可以使用默认情况下烘焙的iriscouch主机。

As you can see Using Geocouch is fairly easy, and a query takes a bounding box like this : 正如您所看到的, 使用Geocouch相当容易,查询采用如下边界框:

http://localhost:5984/places/_design/main/_spatial/points?bbox=0,0,180,90

If you dont want to use geocouch (for some reason), I have successfully used a GeoHash which maps the two dimensions into a one dimensional space. 如果您不想使用geocouch(出于某种原因),我已成功使用GeoHash将两个维度映射到一维空间。 Here is the view code, and here is the query. 是视图代码, 是查询。 As you can see, it is not as elegant, but it is portable across couchdb versions, and it also works. 正如您所看到的,它并不优雅,但它可以在couchdb版本中移植,并且它也可以工作。

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

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