Does CouchDB support multiple range queries?

conditional-statements, couchdb, range

Solution

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.

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.

An alternative solution would be to use couchdb-lucene.

Problem

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. My View function is like this: ``` "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);}}" ``` 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} ``` Here, I am not getting the desired result. I think my startkey and endkey params are wrong. Can anyone help me?

Original source