In CouchDB, you cannot pass the dynamic value of a query parameter into a view (in your case cat = definition). The approach in CouchDB is to create a more general view, and then adjust how the result is sorted when you call the view to get the data you need.
To achieve this, you need to create a custom view in the db design document:
byUserItemCat: { map: function (doc) { if ( !doc.items || doc.items.length === 0 ) return; for ( var i=0; i<doc.items.length; i++ ) { emit(doc.items[i].cat,{doc._id,doc.items[i].date,doc.items[i].text}); } } }
Thus, the above view takes every doc in db, checks that it has an array of elements with content, and then iterates over all the elements of the document. For each element of the element, he finds that he emits cat into the result set as an index, this is important, since we can sort against this index. We can build the result object in any case (the second argument is emit ), and in this case I create an object with a user ID, as well as the date and text of the element.
You would name the view something like this to get all the results:
curl -X GET http://127.0.0.1:5984/<db-name>/_design/<design-doc-name>/_view/byUserItemCat
And if you were just interested in results in which a key parameter (i.e. cat ) would be a "definition":
curl -X GET http://127.0.0.1:5984/<db-name>/_design/<design-doc-name>/_view/byUserItemCat?key="determination"
source share