I Want to query CouchDB and I have a specific need : my query should return the name field of documents corresponding to this condition : the id is equal or contained in a document filed (a list). For example, the field output is the following :

"output": [

I want to get all the documents having in their output field "doc_s102" for example. I wrote a view in a design document :

"backward_by_docid": {
           "map": "function(doc) {if(doc.output) emit(doc.output, doc.name)}"

but this view works only when I have a unique value in the output field. How can I resolve this query ?

Thanks !


you have to iterate over the array:

  if(doc.output) {
      for (var curOutput in doc.output) {
        emit (doc.output[curOutput],doc.name);

make sure that output always is an array (at least [])

.. and, of course use key="xx" instead key=["xxx"]

  • thanks for the answer, it work ! – user162284 Mar 15 '12 at 16:26
  • +1 for this. Worked for me. Thanks okurow. – Vida Dec 17 '15 at 17:37

Your Answer

