CouchDB是否支持多个范围查询? [英] Does CouchDB support multiple range queries?
问题描述
如何在CouchDB中实现多个范围查询?对于单范围条件,startkey和endkey组合可以正常工作,但同一情况不适用于多范围条件。
How are multiple range queries implemented in CouchDB? For a single range condition, startkey and endkey combination works fine, but the same thing is not working with a multiple range condition.
我的视图函数如下:
"function(doc){
if ((doc['couchrest-type'] == 'Item')
&& doc['loan_name']&& doc['loan_period']&&
doc['loan_amount'])
{ emit([doc['template_id'],
doc['loan_name'],doc['loan_period'],
doc['loan_amount']],null);}}"
我需要使用 loan_period
> 5和
<$ c来获取整个文档$ c> loan_amount >30000。我的startkey和endkey参数如下:
I need to get the whole docs with loan_period
> 5 and
loan_amount
> 30000. My startkey and endkey parameters are like this:
params = {:startkey =>["7446567e45dc5155353736cb3d6041c0",nil,5,30000],
:endkey=>["7446567e45dc5155353736cb3d6041c0",{},{},{}],:include_docs => true}
在这里,我没有得到想要的结果。我认为我的startkey和endkey参数是错误的。有人可以帮我吗?
Here, I am not getting the desired result. I think my startkey and endkey params are wrong. Can anyone help me?
推荐答案
CouchDB视图是条目的有序列表。视图上的查询返回该列表的连续切片。因此,不可能应用两个不等式条件。
A CouchDB view is an ordered list of entries. Queries on a view return a contiguous slice of that list. As such, it's not possible to apply two inequality conditions.
假设您的loan_period是一个离散变量,则最好先发出bloat_period来解决这种情况然后每个时期发出一个查询。
Assuming that your loan_period is a discrete variable, this case would probably be best solved by emit'ing the loan_period first and then issuing one query for each period.
另一种解决方案是使用ouchdb-lucene。
An alternative solution would be to use couchdb-lucene.
这篇关于CouchDB是否支持多个范围查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!