Thanks for reply , guys. If i want to select all tv or computer that have price in between 1000 and 2000, ?startkey= [ ["computer", "tv"] , 1000]&endkey=[["computer", "tv"] , 2000]&include_docs=true Is it correct ?
--- On Sat, 10/31/09, Adam Kocoloski <[email protected]> wrote: From: Adam Kocoloski <[email protected]> Subject: Re: CouchDB equivalent dynamic SQL To: [email protected] Date: Saturday, October 31, 2009, 12:59 AM 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
