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
>