views:

159

answers:

1

Short of doing client-side filtering or POSTing a one-off map/reduce (which would result in a table scan), is there any way to query for documents tagged with tagA or tagB?

+3  A: 

issue a POST request with a body of {"keys":["tagA","tagB"],"include_docs":true} to a view with a map of function(doc){doc.tags.forEach(function(tag){emit(tag,1)})}

that should do yah :)

from query options section in http://wiki.apache.org/couchdb/HTTP_view_API

mikeal
Correct me if I'm wrong, but I thought that would return all documents tagged with both `tagA` AND `tagB`, no? "... [can be posted] to retrieve just the view rows matching that set of keys"
David Wolever
@David The one point mikeal semi-forgot is that this is really a bulk request. You're POST'ing to _all_docs, which basically says "give me all of the documents whose _id matches anything in this array". More info at http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API Also, if you start to get into more complex queries, then take a look at couchdb-lucene. Cheers.
Sam Bisbee
Ah, gotcha. Thanks.
David Wolever
no, you don't post to all docs, you post to the view. Search for "keys" in the docs http://wiki.apache.org/couchdb/HTTP_view_APIyou can use the same POST style interface available for bulk with the view index.
mikeal