incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randall Leeds <randall.le...@gmail.com>
Subject Re: How to pass parameters to views?
Date Mon, 06 Dec 2010 19:23:15 GMT
Oh, yeah. So, to answer your other question. Use a _list function.

On Mon, Dec 6, 2010 at 11:22, Randall Leeds <randall.leeds@gmail.com> wrote:
> It cannot be done due to the nature of views and the way couchdb does
> map-reduce.
> View output should be deterministic and as such cannot depend on
> query-time parameters.
> This is what allows the index to be build incrementally and the reason
> why a _list function runs through the whole result set every time you
> query it but views can be retrieved with ?stale=ok and aren't re-run
> for every request.
>
> On Mon, Dec 6, 2010 at 09:28, Wordit Ltd <wordituk@googlemail.com> wrote:
>> Can parameters be passed to views? I know you can use them in updaters.
>> I hoped this would work, but it did not:
>>
>> function(doc, req) {
>> var myparam = req.query.myparam;
>> ...
>>
>> URL: .../view_name?myparam="foo"
>>
>>
>> I need to pass two parameters to a for loop which is pulling data from
>> an array/list.
>> I have data stored in the array "words".
>>
>> function(doc) {
>>  for (i=0; i < doc.words.length;i++) {
>>  emit(i, doc.words[i]);
>>  }
>> }
>>
>> This outputs ALL items in the array. I want to pass in A and B as
>> params to the for loop.
>> Can this be done, or is there another way to achieve it?
>>
>> Thanks,
>>
>> Marcus
>>
>

Mime
View raw message