You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by go canal <go...@yahoo.com> on 2009/09/23 11:37:15 UTC

is there a way to pass a request parameter to a view ?

Hello,
use case:
  - change the value of a field of documents

question:
  is there a way to pass a request parameter to the view ?

I would imagine some like this:
  /db/view?key=value
then in the view function (doc) {
   if (doc match some criteria)
     doc.Type = value;
}
in the reduce function, I can then return the # of changed documents....

But the view function only accepts one argument 'doc'. 

Do I have to get a list, then get each document, then put ? does not seem to be efficient.

 rgds,
canal



      

Re: is there a way to pass a request parameter to a view ?

Posted by go canal <go...@yahoo.com>.
I see, I got the wrong impression :-(
 rgds,
canal




________________________________
From: Benoit Chesneau <bc...@gmail.com>
To: user@couchdb.apache.org
Sent: Friday, September 25, 2009 2:03:39 PM
Subject: Re: is there a way to pass a request parameter to a view ?

On Fri, Sep 25, 2009 at 7:51 AM, go canal <go...@yahoo.com> wrote:
> thanks for confirming, I think it is acceptable, though not ideal.
>
>
> Just wondering, since we can modify individual field with Futon, why don't we expose the API ? rgds,
> canal
>
>
afaik futon update the full doc.

- benoit



      

Re: is there a way to pass a request parameter to a view ?

Posted by Benoit Chesneau <bc...@gmail.com>.
On Fri, Sep 25, 2009 at 7:51 AM, go canal <go...@yahoo.com> wrote:
> thanks for confirming, I think it is acceptable, though not ideal.
>
>
> Just wondering, since we can modify individual field with Futon, why don't we expose the API ? rgds,
> canal
>
>
afaik futon update the full doc.

- benoit

Re: is there a way to pass a request parameter to a view ?

Posted by go canal <go...@yahoo.com>.
an 'ideal' solution in my thinking is,  I can pass some request parameters to a view, which in turn modifies the documents, without passing back and forth the documents at all. 


I agree that actual performance impact is not significant. A small project I am working on needs to manage only 7000+ documents. If the metadata of every document is about 500 bytes, this is only 3MB+.  Even 30MB data for 70K documents may still manageable.

however a server side API can simplify the application development at the client side. that's what I mean by 'ideal'.
 rgds,
canal




________________________________
From: Jan Lehnardt <ja...@apache.org>
To: user@couchdb.apache.org
Sent: Friday, September 25, 2009 3:59:01 PM
Subject: Re: is there a way to pass a request parameter to a view ?


On 25 Sep 2009, at 07:51, go canal wrote:

> thanks for confirming, I think it is acceptable, though not ideal.
> 
> Just wondering, since we can modify individual field with Futon, why don't we expose the API ? rgds,

The only thing that is not ideal about this is transport cost and memory usage between the client and CouchDB. This issue came up a few times and we asked that the reporter go and build a working system and then show a real-world benchmark (heh) that indicates that this particular behaviour of CouchDB is a bottleneck. Until then, this is premature optimization that should be avoided.

Cheers
Jan
--


> canal
> 
> 
> 
> 
> ________________________________
> From: Jesse Hallett <ha...@gmail.com>
> To: user@couchdb.apache.org
> Sent: Friday, September 25, 2009 9:54:10 AM
> Subject: Re: is there a way to pass a request parameter to a view ?
> 
> Sorry, you have to upload the whole doc.  You do not have to send
> attachments again though.
> 
> On Sep 24, 2009 6:14 PM, "go canal" <go...@yahoo.com> wrote:
> 
> thanks !
> 
> Can I use this bulk update to change a field without uploading the full doc:
> 
> {
>  "docs": [
>    {"_id": "1", "_rev": "1-2089673485", "integer": 2},
>    {"_id": "2", "_rev": "1-2063452834", "integer": 3, "string": "3"}
>  ]
> }
> 
> So for doc _id 1, I only change 'integer'; will the rest be kept intact, or
> CouchDB will actually create a new doc with 'integer' only ?
> rgds,
> canal
> 
> 
> 
> 
> ________________________________
> From: Jan Lehnardt <ja...@apache.org>
> 
> To: user@couchdb.apache.org
> Sent: Thursday, September 24, 2009 7:02:30 PM
> 
> Subject: Re: is there a way to pass a request parameter to a view ?
> 
> On 24 Sep 2009, at 12:40, Matt Goodall wrote: > 2009/9/24 Jan Lehnardt <
> jan@apache.org>: >> >> On 2...
> 
> 
> 


      

Re: is there a way to pass a request parameter to a view ?

Posted by Jan Lehnardt <ja...@apache.org>.
On 25 Sep 2009, at 07:51, go canal wrote:

> thanks for confirming, I think it is acceptable, though not ideal.
>
> Just wondering, since we can modify individual field with Futon, why  
> don't we expose the API ? rgds,

The only thing that is not ideal about this is transport cost and  
memory usage between the client and CouchDB. This issue came up a few  
times and we asked that the reporter go and build a working system and  
then show a real-world benchmark (heh) that indicates that this  
particular behaviour of CouchDB is a bottleneck. Until then, this is  
premature optimization that should be avoided.

Cheers
Jan
--


> canal
>
>
>
>
> ________________________________
> From: Jesse Hallett <ha...@gmail.com>
> To: user@couchdb.apache.org
> Sent: Friday, September 25, 2009 9:54:10 AM
> Subject: Re: is there a way to pass a request parameter to a view ?
>
> Sorry, you have to upload the whole doc.  You do not have to send
> attachments again though.
>
> On Sep 24, 2009 6:14 PM, "go canal" <go...@yahoo.com> wrote:
>
> thanks !
>
> Can I use this bulk update to change a field without uploading the  
> full doc:
>
> {
>  "docs": [
>    {"_id": "1", "_rev": "1-2089673485", "integer": 2},
>    {"_id": "2", "_rev": "1-2063452834", "integer": 3, "string": "3"}
>  ]
> }
>
> So for doc _id 1, I only change 'integer'; will the rest be kept  
> intact, or
> CouchDB will actually create a new doc with 'integer' only ?
> rgds,
> canal
>
>
>
>
> ________________________________
> From: Jan Lehnardt <ja...@apache.org>
>
> To: user@couchdb.apache.org
> Sent: Thursday, September 24, 2009 7:02:30 PM
>
> Subject: Re: is there a way to pass a request parameter to a view ?
>
> On 24 Sep 2009, at 12:40, Matt Goodall wrote: > 2009/9/24 Jan  
> Lehnardt <
> jan@apache.org>: >> >> On 2...
>
>
>


Re: is there a way to pass a request parameter to a view ?

Posted by go canal <go...@yahoo.com>.
thanks for confirming, I think it is acceptable, though not ideal.


Just wondering, since we can modify individual field with Futon, why don't we expose the API ? rgds,
canal




________________________________
From: Jesse Hallett <ha...@gmail.com>
To: user@couchdb.apache.org
Sent: Friday, September 25, 2009 9:54:10 AM
Subject: Re: is there a way to pass a request parameter to a view ?

Sorry, you have to upload the whole doc.  You do not have to send
attachments again though.

On Sep 24, 2009 6:14 PM, "go canal" <go...@yahoo.com> wrote:

thanks !

Can I use this bulk update to change a field without uploading the full doc:

{
  "docs": [
    {"_id": "1", "_rev": "1-2089673485", "integer": 2},
    {"_id": "2", "_rev": "1-2063452834", "integer": 3, "string": "3"}
  ]
}

So for doc _id 1, I only change 'integer'; will the rest be kept intact, or
CouchDB will actually create a new doc with 'integer' only ?
rgds,
canal




________________________________
From: Jan Lehnardt <ja...@apache.org>

To: user@couchdb.apache.org
Sent: Thursday, September 24, 2009 7:02:30 PM

Subject: Re: is there a way to pass a request parameter to a view ?

On 24 Sep 2009, at 12:40, Matt Goodall wrote: > 2009/9/24 Jan Lehnardt <
jan@apache.org>: >> >> On 2...



      

Re: is there a way to pass a request parameter to a view ?

Posted by Jesse Hallett <ha...@gmail.com>.
Sorry, you have to upload the whole doc.  You do not have to send
attachments again though.

On Sep 24, 2009 6:14 PM, "go canal" <go...@yahoo.com> wrote:

thanks !

Can I use this bulk update to change a field without uploading the full doc:

{
  "docs": [
    {"_id": "1", "_rev": "1-2089673485", "integer": 2},
    {"_id": "2", "_rev": "1-2063452834", "integer": 3, "string": "3"}
  ]
}

So for doc _id 1, I only change 'integer'; will the rest be kept intact, or
CouchDB will actually create a new doc with 'integer' only ?
rgds,
canal




________________________________
From: Jan Lehnardt <ja...@apache.org>

To: user@couchdb.apache.org
Sent: Thursday, September 24, 2009 7:02:30 PM

Subject: Re: is there a way to pass a request parameter to a view ?

On 24 Sep 2009, at 12:40, Matt Goodall wrote: > 2009/9/24 Jan Lehnardt <
jan@apache.org>: >> >> On 2...

Re: is there a way to pass a request parameter to a view ?

Posted by go canal <go...@yahoo.com>.
thanks !

Can I use this bulk update to change a field without uploading the full doc:

{
  "docs": [
    {"_id": "1", "_rev": "1-2089673485", "integer": 2},
    {"_id": "2", "_rev": "1-2063452834", "integer": 3, "string": "3"}
  ]
} 

So for doc _id 1, I only change 'integer'; will the rest be kept intact, or CouchDB will actually create a new doc with 'integer' only ?
rgds,
canal 




________________________________
From: Jan Lehnardt <ja...@apache.org>
To: user@couchdb.apache.org
Sent: Thursday, September 24, 2009 7:02:30 PM
Subject: Re: is there a way to pass a request parameter to a view ?


On 24 Sep 2009, at 12:40, Matt Goodall wrote:

> 2009/9/24 Jan Lehnardt <ja...@apache.org>:
>>
>> On 24 Sep 2009, at 02:31, go canal wrote:
>>
>>> no problem. the link is still very useful.
>>>
>>> I found 'HTTP_Bulk_Document_API' but empty page now
>>> http://wiki.apache.org/couchdb/%5BHTTP_Bulk_Document_API
>>
>> Where di you find this (broken) link? The correct link is
>> http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
>> and it is not empty :)
>
> It was here, http://wiki.apache.org/couchdb/HTTP_Document_API, and I
> just fixed the link. (I happened to be looking at the wiki so simply
> searched for the bad link text.)
>

D’oh me. Thanks Matt!

Cheers
Jan
--


      

Re: is there a way to pass a request parameter to a view ?

Posted by Jan Lehnardt <ja...@apache.org>.
On 24 Sep 2009, at 12:40, Matt Goodall wrote:

> 2009/9/24 Jan Lehnardt <ja...@apache.org>:
>>
>> On 24 Sep 2009, at 02:31, go canal wrote:
>>
>>> no problem. the link is still very useful.
>>>
>>> I found 'HTTP_Bulk_Document_API' but empty page now
>>> http://wiki.apache.org/couchdb/%5BHTTP_Bulk_Document_API
>>
>> Where di you find this (broken) link? The correct link is
>> http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
>> and it is not empty :)
>
> It was here, http://wiki.apache.org/couchdb/HTTP_Document_API, and I
> just fixed the link. (I happened to be looking at the wiki so simply
> searched for the bad link text.)
>

D’oh me. Thanks Matt!

Cheers
Jan
--


Re: is there a way to pass a request parameter to a view ?

Posted by Matt Goodall <ma...@gmail.com>.
2009/9/24 Jan Lehnardt <ja...@apache.org>:
>
> On 24 Sep 2009, at 02:31, go canal wrote:
>
>> no problem. the link is still very useful.
>>
>> I found 'HTTP_Bulk_Document_API' but empty page now
>> http://wiki.apache.org/couchdb/%5BHTTP_Bulk_Document_API
>
> Where di you find this (broken) link? The correct link is
> http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
> and it is not empty :)

It was here, http://wiki.apache.org/couchdb/HTTP_Document_API, and I
just fixed the link. (I happened to be looking at the wiki so simply
searched for the bad link text.)

- Matt

Re: is there a way to pass a request parameter to a view ?

Posted by Jan Lehnardt <ja...@apache.org>.
On 24 Sep 2009, at 02:31, go canal wrote:

> no problem. the link is still very useful.
>
> I found 'HTTP_Bulk_Document_API' but empty page now http://wiki.apache.org/couchdb/%5BHTTP_Bulk_Document_API

Where di you find this (broken) link? The correct link is
http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
and it is not empty :)

Cheers
Jan
--


>
> any idea what is this for ?
> thanks.
> canal
>
>
>
>
> ________________________________
> From: Simon Metson <si...@googlemail.com>
> To: user@couchdb.apache.org
> Sent: Thursday, September 24, 2009 6:06:31 AM
> Subject: Re: is there a way to pass a request parameter to a view ?
>
> Sorry - jet lag causing read fails...
>
> On 23 Sep 2009, at 10:12, Jesse Hallett wrote:
>
>> The most efficient way to update a lot of docs currently is to  
>> download all
>> of the docs via a view query - try the `includedocs` query  
>> parameter - and
>> then to bulk update those docs with a single POST request.
>>
>> There is no mechanism for updating through the view directly.
>>
>> On Sep 23, 2009 5:40 AM, "Simon Metson"  
>> <si...@googlemail.com> wrote:
>>
>> Hi
>>       CouchDB takes care of the view slicing for you (see
>> http://wiki.apache.org/couchdb/HTTP_view_API. You'd write a view  
>> that emits
>> some key:values, and then do the query you describe (?key=foo) to  
>> return
>> only the values with key = foo. You can also do startkey=foo and  
>> endkey=bar
>> to get a slice of the view (e.g. look for continuous data in a  
>> range). You
>> don't need to worry about this in writing your view, since the view  
>> is
>> generated for all keys.
>> Cheers
>> Simon
>>
>> On 23 Sep 2009, at 04:37, go canal wrote: > Hello, > use case: >  -  
>> change
>> the value of a field o...
>
>


Re: is there a way to pass a request parameter to a view ?

Posted by go canal <go...@yahoo.com>.
no problem. the link is still very useful.
 
I found 'HTTP_Bulk_Document_API' but empty page now http://wiki.apache.org/couchdb/%5BHTTP_Bulk_Document_API 

any idea what is this for ?
thanks.
canal 




________________________________
From: Simon Metson <si...@googlemail.com>
To: user@couchdb.apache.org
Sent: Thursday, September 24, 2009 6:06:31 AM
Subject: Re: is there a way to pass a request parameter to a view ?

Sorry - jet lag causing read fails...

On 23 Sep 2009, at 10:12, Jesse Hallett wrote:

> The most efficient way to update a lot of docs currently is to download all
> of the docs via a view query - try the `includedocs` query parameter - and
> then to bulk update those docs with a single POST request.
> 
> There is no mechanism for updating through the view directly.
> 
> On Sep 23, 2009 5:40 AM, "Simon Metson" <si...@googlemail.com> wrote:
> 
> Hi
>      CouchDB takes care of the view slicing for you (see
> http://wiki.apache.org/couchdb/HTTP_view_API. You'd write a view that emits
> some key:values, and then do the query you describe (?key=foo) to return
> only the values with key = foo. You can also do startkey=foo and endkey=bar
> to get a slice of the view (e.g. look for continuous data in a range). You
> don't need to worry about this in writing your view, since the view is
> generated for all keys.
> Cheers
> Simon
> 
> On 23 Sep 2009, at 04:37, go canal wrote: > Hello, > use case: >  - change
> the value of a field o...


      

Re: is there a way to pass a request parameter to a view ?

Posted by Simon Metson <si...@googlemail.com>.
Sorry - jet lag causing read fails...

On 23 Sep 2009, at 10:12, Jesse Hallett wrote:

> The most efficient way to update a lot of docs currently is to  
> download all
> of the docs via a view query - try the `includedocs` query parameter  
> - and
> then to bulk update those docs with a single POST request.
>
> There is no mechanism for updating through the view directly.
>
> On Sep 23, 2009 5:40 AM, "Simon Metson" <si...@googlemail.com>  
> wrote:
>
> Hi
>       CouchDB takes care of the view slicing for you (see
> http://wiki.apache.org/couchdb/HTTP_view_API. You'd write a view  
> that emits
> some key:values, and then do the query you describe (?key=foo) to  
> return
> only the values with key = foo. You can also do startkey=foo and  
> endkey=bar
> to get a slice of the view (e.g. look for continuous data in a  
> range). You
> don't need to worry about this in writing your view, since the view is
> generated for all keys.
> Cheers
> Simon
>
> On 23 Sep 2009, at 04:37, go canal wrote: > Hello, > use case: >  -  
> change
> the value of a field o...


Re: is there a way to pass a request parameter to a view ?

Posted by go canal <go...@yahoo.com>.
if I have to use POST, does this mean I have to post everyting again, including attachements ?
 rgds,
canal 




________________________________
From: Jesse Hallett <ha...@gmail.com>
To: user@couchdb.apache.org
Sent: Wednesday, September 23, 2009 11:12:08 PM
Subject: Re: is there a way to pass a request parameter to a view ?

The most efficient way to update a lot of docs currently is to download all
of the docs via a view query - try the `includedocs` query parameter - and
then to bulk update those docs with a single POST request.

There is no mechanism for updating through the view directly.

On Sep 23, 2009 5:40 AM, "Simon Metson" <si...@googlemail.com> wrote:

Hi
      CouchDB takes care of the view slicing for you (see
http://wiki.apache.org/couchdb/HTTP_view_API. You'd write a view that emits
some key:values, and then do the query you describe (?key=foo) to return
only the values with key = foo. You can also do startkey=foo and endkey=bar
to get a slice of the view (e.g. look for continuous data in a range). You
don't need to worry about this in writing your view, since the view is
generated for all keys.
Cheers
Simon

On 23 Sep 2009, at 04:37, go canal wrote: > Hello, > use case: >  - change
the value of a field o...



      

Re: is there a way to pass a request parameter to a view ?

Posted by go canal <go...@yahoo.com>.
thanks. 
could you pls elaborate more on include_docs ? how should I use this ?
rgds,
canal 




________________________________
From: Jesse Hallett <ha...@gmail.com>
To: user@couchdb.apache.org
Sent: Wednesday, September 23, 2009 11:12:08 PM
Subject: Re: is there a way to pass a request parameter to a view ?

The most efficient way to update a lot of docs currently is to download all
of the docs via a view query - try the `includedocs` query parameter - and
then to bulk update those docs with a single POST request.

There is no mechanism for updating through the view directly.

On Sep 23, 2009 5:40 AM, "Simon Metson" <si...@googlemail.com> wrote:

Hi
      CouchDB takes care of the view slicing for you (see
http://wiki.apache.org/couchdb/HTTP_view_API. You'd write a view that emits
some key:values, and then do the query you describe (?key=foo) to return
only the values with key = foo. You can also do startkey=foo and endkey=bar
to get a slice of the view (e.g. look for continuous data in a range). You
don't need to worry about this in writing your view, since the view is
generated for all keys.
Cheers
Simon

On 23 Sep 2009, at 04:37, go canal wrote: > Hello, > use case: >  - change
the value of a field o...



      

Re: is there a way to pass a request parameter to a view ?

Posted by Jesse Hallett <ha...@gmail.com>.
The most efficient way to update a lot of docs currently is to download all
of the docs via a view query - try the `includedocs` query parameter - and
then to bulk update those docs with a single POST request.

There is no mechanism for updating through the view directly.

On Sep 23, 2009 5:40 AM, "Simon Metson" <si...@googlemail.com> wrote:

Hi
       CouchDB takes care of the view slicing for you (see
http://wiki.apache.org/couchdb/HTTP_view_API. You'd write a view that emits
some key:values, and then do the query you describe (?key=foo) to return
only the values with key = foo. You can also do startkey=foo and endkey=bar
to get a slice of the view (e.g. look for continuous data in a range). You
don't need to worry about this in writing your view, since the view is
generated for all keys.
Cheers
Simon

On 23 Sep 2009, at 04:37, go canal wrote: > Hello, > use case: >  - change
the value of a field o...

Re: is there a way to pass a request parameter to a view ?

Posted by Simon Metson <si...@googlemail.com>.
Hi
	CouchDB takes care of the view slicing for you (see http://wiki.apache.org/couchdb/HTTP_view_API 
. You'd write a view that emits some key:values, and then do the query  
you describe (?key=foo) to return only the values with key = foo. You  
can also do startkey=foo and endkey=bar to get a slice of the view  
(e.g. look for continuous data in a range). You don't need to worry  
about this in writing your view, since the view is generated for all  
keys.
Cheers
Simon

On 23 Sep 2009, at 04:37, go canal wrote:

> Hello,
> use case:
>  - change the value of a field of documents
>
> question:
>  is there a way to pass a request parameter to the view ?
>
> I would imagine some like this:
>  /db/view?key=value
> then in the view function (doc) {
>   if (doc match some criteria)
>     doc.Type = value;
> }
> in the reduce function, I can then return the # of changed  
> documents....
>
> But the view function only accepts one argument 'doc'.
>
> Do I have to get a list, then get each document, then put ? does not  
> seem to be efficient.
>
> rgds,
> canal
>
>
>