You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Steven Prentice <st...@gmail.com> on 2010/07/19 01:12:02 UTC

using req.query to filter a list function in couchDB 0.10.0

Hi,
I am trying to use a list function to filter the results of a view in my
database. I have developed the following code, but keep getting a reference
error when making a request:

Request = curl -X GET
'..../_design/dates/_list/param/audit_resource_subresource_with_criteria?as="TestUser"'

(param is the name of my list function)

the function looks like this...what I am trying to do is allow someone to
enter the name of the user to filter the view for just rows where the
accessingsystem field = what is entered:

function(head, req)
{
    var accessingsystem = req.query['as'];
    var row;
    while(row = getRow())
    {
        if (as && row.value[1] != as)
        {
            continue;
        }
        send(row.value);
    }
}

the error i get is {"code":500,"error":"render_error","reason":"function
raised error: ReferenceError: as is not defined"}

any help = much appreciated!
Steve

Re: using req.query to filter a list function in couchDB 0.10.0

Posted by Steven Prentice <st...@gmail.com>.
Oh yes, you were right, wow I feel so noob right now, thanks you probably
saved me a day's worth of frustration =]
cheers
steve

On Mon, Jul 19, 2010 at 9:22 AM, J Chris Anderson <jc...@gmail.com> wrote:

>
> On Jul 18, 2010, at 4:12 PM, Steven Prentice wrote:
>
> > Hi,
> > I am trying to use a list function to filter the results of a view in my
> > database. I have developed the following code, but keep getting a
> reference
> > error when making a request:
> >
> > Request = curl -X GET
> >
> '..../_design/dates/_list/param/audit_resource_subresource_with_criteria?as="TestUser"'
> >
> > (param is the name of my list function)
> >
> > the function looks like this...what I am trying to do is allow someone to
> > enter the name of the user to filter the view for just rows where the
> > accessingsystem field = what is entered:
> >
> > function(head, req)
> > {
> >    var accessingsystem = req.query['as'];
> >    var row;
> >    while(row = getRow())
> >    {
> >        if (as && row.value[1] != as)
> >        {
> >            continue;
> >        }
> >        send(row.value);
> >    }
> > }
> >
> > the error i get is {"code":500,"error":"render_error","reason":"function
> > raised error: ReferenceError: as is not defined"}
> >
>
> looks like a garden-variety JS error:
>
> "as" in the loop body should be replaced with accessingsystem
>
> > any help = much appreciated!
> > Steve
>
>

Re: using req.query to filter a list function in couchDB 0.10.0

Posted by J Chris Anderson <jc...@gmail.com>.
On Jul 18, 2010, at 4:12 PM, Steven Prentice wrote:

> Hi,
> I am trying to use a list function to filter the results of a view in my
> database. I have developed the following code, but keep getting a reference
> error when making a request:
> 
> Request = curl -X GET
> '..../_design/dates/_list/param/audit_resource_subresource_with_criteria?as="TestUser"'
> 
> (param is the name of my list function)
> 
> the function looks like this...what I am trying to do is allow someone to
> enter the name of the user to filter the view for just rows where the
> accessingsystem field = what is entered:
> 
> function(head, req)
> {
>    var accessingsystem = req.query['as'];
>    var row;
>    while(row = getRow())
>    {
>        if (as && row.value[1] != as)
>        {
>            continue;
>        }
>        send(row.value);
>    }
> }
> 
> the error i get is {"code":500,"error":"render_error","reason":"function
> raised error: ReferenceError: as is not defined"}
> 

looks like a garden-variety JS error:

"as" in the loop body should be replaced with accessingsystem

> any help = much appreciated!
> Steve