Correct. In retrospect, I am looking for an idiom or preferred way to achieve a dynamic view. My example states I'd like to query by type="post" OR tag="tag1", but I'd like the key values to be dynamic. My next request might be type="photo" OR tag="tag2". This would return IDs 1, 2 and 3.
I understand temporary views are an option, but they aren't efficient. Would it be best to have two permanent views which can be queried by key and merge the results in the client? I could have one permanent view by_type and another by_tag. This technique looks to be described in the blog post below, but its from 2009. http://sitr.us/2009/06/30/database-queries-the-couchdb-way.html Thanks, Simeon On Sat, Feb 19, 2011 at 9:49 AM, Robert Newson <[email protected]> wrote: > While this; > > function(doc) { > if (doc.type=="post") { > emit(null, null); > } > for (var i=0; i<doc.tags.length; i++) { > if (doc.tags[i] == "tag1") { > emit(null, null); > } > } > } > > achieves your stated goal, I don't think it's what you're really > asking for, right? > > B. > > On 19 February 2011 16:17, Simeon F. Willbanks <[email protected]> wrote: >> Hello, >> >> I'm trying to fetch a set of documents with OR logic. For example, >> fetch all documents with type="post" OR tag="tag1". Here are a few >> example documents with rev omitted for brevity: >> >> { >> "_id": 1, >> "type": "post", >> "tags": [ >> "tag1", >> "tag2" >> ] >> } >> >> { >> "_id": 2, >> "type": "photo", >> "tags": [ >> "tag1", >> "tag3" >> ] >> } >> >> { >> "_id": 3, >> "type": "photo", >> "tags": [ >> "tag4", >> "tag5" >> ] >> } >> >> I'd like to fetch documents with the ids 1 and 2. >> >> It seems this method will be my starting point: >> "A JSON structure of {"keys": ["key1", "key2", ...]} can be posted to >> any user defined view or _all_docs to retrieve just the view rows >> matching that set of keys. Rows are returned in the order of the keys >> specified. Combining this feature with include_docs=true results in >> the so-called multi-document-fetch feature." >> http://wiki.apache.org/couchdb/HTTP_view_API >> >> Am I correct so far? If yes, how would I define my map function? Would >> I call emit multiple times and possibly use a group=true parameter? >> >> Thanks, >> Simeon >> >
