具有多个键值的CouchDB视图查询 [英] CouchDB view query with multiple key values

查看:74
本文介绍了具有多个键值的CouchDB视图查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在尝试创建视图和查询以适合此SQL查询:

I am currently trying to create a view and query to fit this SQL query:

SELECT * FROM articles
WHERE articles.location="NY" OR articles.location="CA"
ORDER BY articles.release_date DESC

我尝试创建带有复杂键的视图:

I tried to create a view with a complex key:

function(doc) { 
  if(doc.type == "Article") { 
    emit([doc.location, doc.release_date], doc) 
  }
}

然后使用 startkey endkey 检索一个位置并在发布日期排序结果。

And then using startkey and endkey to retrieve one location and ordering the result on the release date.

.../_view/articles?startkey=["NY", {}]&endkey=["NY"]&limit=5&descending=true

这很好用。

但是,如何模仿我的视图发送多个开始键和结束键

However, how can I send multiple startkeys and endkeys to my view in order to mimic

WHERE article.locatio n = NY或article.location = CA

推荐答案

我的大敌,

此外,永远不可能根据条件A进行查询,然后按CouchDB中的条件B进行排序。作为这种不便的交换,CouchDB保证了可扩展,可靠,对数的查询时间。您可以选择。

Furthermore, it is never possible to query by criteria A and then sort by criteria B in CouchDB. In exchange for that inconvenience, CouchDB guarantees scalable, dependable, logarithmic query times. You have a choice.


  • 将视图输出存储在自己的数据库中,并创建新视图进行排序根据条件B

  • ,对行进行排序,可以是

    • 排序客户端,一旦您在 _list 函数中收到行

    • 在服务器端进行排序。很棒,但是请记住,它最终并没有扩展性。如果您有数百万行,则 _list 函数可能会崩溃。

    • Store the view output in its own database, and make a new view to sort by criteria B
    • or, sort the rows afterward, which can be either
      • Sort client-side, once you receive the rows
      • Sort server-side, in a _list function. The is great, but remember it's not ultimately scalable. If you have millions of rows, the _list function will probably crash.

      这篇关于具有多个键值的CouchDB视图查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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