tags:

views:

64

answers:

2

Hi,

Is it possible to use similiar query in CouchDB? Like use two keys?

SELECT field FROM table WHERE value1="key1" OR value2="key2"

I was always using only one key.

function(doc) {

    emit(doc.title, doc);

}

Thank you.

A: 

Yes. Something like this should do the trick if I understand your question:

function(doc) {
  a = (doc.value1 && doc.value1 == "key1");
  b = (doc.value2 && doc.value2 == "key2");
  if (a || b) {
    emit(doc._id,doc.title);
  }
}

Only emit the documents or values you need.

duluthian
+1  A: 

In CouchDB 0.9 and above you can POST to a view (or _all_docs) with a body like:

{"keys": ["key1", "key2", ...]}

In order to retrieve the set of rows with the matching keys.

llasram