On Oct 30, 2009, at 1:36 PM, Duy Nguyen wrote:
Hi guys,
I have a troublesome sql query that needs to translate to couchDB
map/reduce
SELECT * FROM PRODUCTSWHERE [ PRICE ] AND [TYPE]'
Please note that Price and Type are dynamically generated depend on
user inputs. ( i.e TYPEcan be 100 < PRICE < 1000, or 1 < PRICE <
100, or 1000 < PRICE < 10000. TYPE could be 'computer' , 'tv' etc..)
I can not do dynamically query on the fly with CouchDB. what is the
best way to solve this problem ?
Hi Duy, it won't always be a perfect translation. But CouchDB's
compound view keys should be able to help you in this situation. In
your map, emit([doc.type, doc.price], null) and then query the view with
?startkey=["computer", 1000]&endkey=["computer", 10000]
&include_docs=true
or
?startkey=["tv", 100]&endkey=["tv", 1000]&include_docs=true
Best, Adam