You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Avi Flax <av...@arc90.com> on 2008/07/20 22:24:22 UTC

How to use View URL Query Parameters?

Specifically, I don't understand how to use "key".

Let's say I want to get all Comment documents which are tagged with "doofus".

I figured I'd create a "views" key in a design doc that looked
something like this:

{
   "for_tag":
   {
       "map": "function(doc) { if (doc.tags.indexOf(key) != -1)
emit(null, doc) }"
   }
}

and then GET this URL:
http://couchdb:5984/blog/_view/comments/for_tag?key=%22doofus%22

But it's returning 0 rows. I know I must be missing something here.

Apologize if this is a FAQ or is just so obvious it doesn't even need
to be. I think perhaps I need to take a break from the computer for a
couple of hours.

Thanks,
Avi

-- 
Avi Flax » Lead Technologist » Partner » Arc90 » http://arc90.com

Re: How to use View URL Query Parameters?

Posted by Avi Flax <av...@arc90.com>.
Ohhh, OK, I think I get it now. I didn't understand that the "key" URL
Query Parameter was referring to the "key" column of each view result
table. Makes sense now.

Now I'm wondering how to limit results with two parameters, but I
think that'd be a separate thread.

Thanks Chris!

Avi

Re: How to use View URL Query Parameters?

Posted by Chris Anderson <jc...@grabb.it>.
Avi,

Try this:

function(doc) {
  doc.tags && doc.tags.forEach(function(tag){
    emit(tag,null);
  });
}

and read this: http://wiki.apache.org/couchdb/ViewCollation

one query can pull out all view rows with the tag you use as the key param.

Chris

On Sun, Jul 20, 2008 at 4:24 PM, Avi Flax <av...@arc90.com> wrote:
> Specifically, I don't understand how to use "key".
>
> Let's say I want to get all Comment documents which are tagged with "doofus".
>
> I figured I'd create a "views" key in a design doc that looked
> something like this:
>
> {
>   "for_tag":
>   {
>       "map": "function(doc) { if (doc.tags.indexOf(key) != -1)
> emit(null, doc) }"
>   }
> }
>
> and then GET this URL:
> http://couchdb:5984/blog/_view/comments/for_tag?key=%22doofus%22
>
> But it's returning 0 rows. I know I must be missing something here.
>
> Apologize if this is a FAQ or is just so obvious it doesn't even need
> to be. I think perhaps I need to take a break from the computer for a
> couple of hours.
>
> Thanks,
> Avi
>
> --
> Avi Flax » Lead Technologist » Partner » Arc90 » http://arc90.com
>



-- 
Chris Anderson
http://jchris.mfdz.com