Ph0en1x
Ph0en1x

Reputation: 10087

query CouchDB data by several key and order data by another field

General idea, Is that I need to select data by several values and sort it by date.

I need to query couchdb something like this SQL query

Select * from TABLE where Val = "val1" OR Val = "val2" order by Date

So I have a map function looks like

if(doc.type == 'item'){
  emit([doc.val, doc.date], doc);
}

Think it should be something like

?startkey=[['val1','val2']]&endkey=[['val1','val2'],{}]

or

{keys: [['val1',{}],['val2',{}]]}

Is it possible? Maybe some other variannts exist - hot to solve this problem? Thanks.

Upvotes: 0

Views: 139

Answers (1)

Victor Nicollet
Victor Nicollet

Reputation: 24587

This is impossible in CouchDB. You will have to run two queries (possibly as a single bulk request) and perform the final ordering on the client (it is a linear-time operation).

Upvotes: 1

Related Questions