couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vivek Pathak <vpat...@orgmeta.com>
Subject Re: simultaneously run update handler and update doc content
Date Wed, 20 Nov 2013 07:46:06 GMT

On 11/20/2013 02:40 AM, Vivek Pathak wrote:
>
> I have an update handler.
> |{
>     "|_id|":|"_design/compnbd"|,
>     "|_rev|":|"36-3321da9588a5a7b3fef8789bdfefe18d"|,
>     "|updates|":|{
>         "|timestamp|":|"function(doc, req) {\n    if( doc.type == \"profile\" ) { \n
       var d = new Date();\n        doc.serverISO8601time = d.toISOString(); \n        doc.serverTime
= d.getTime() / 1000 ;\n    }\n    return [doc , ''] ;\n} \n"|
>     }|,
>     "|language|":|"javascript"|,
>     "|views|":|{
>        // removed ...
>     }
> }
> ||
>
> The function is copied here for convenience:
> function(doc, req) {
>     if( doc.type == "profile" ) {
>         var d = new Date();
>         doc.serverISO8601time = d.toISOString();
>         doc.serverTime = d.getTime() / 1000 ;
>     }
>     return [doc , ''] ;

The return is an array of doc and empty string  (empty string was messed 
up in copy paste to email) - but the same behavior happens if it were "OK"

> }
>
>
> I run the following commands:
>
>    curl -s 'http://localhost:5984/i7rmdb/testid' > /tmp/2.json
>
>    cat /tmp/2.json
> {"_id":"testid","_rev":"5-71ee77bc43fc698a935abc60dc33a82c","type":"profile","text":"hello
 123","serverISO8601time":"2013-11-20T07:29:35.497Z","serverTime":1384932575.496999979}
>
> Now I edit the document.
>
>    cat /tmp/2.json
> {"_id":"testid","_rev":"5-71ee77bc43fc698a935abc60dc33a82c","type":"profile","text":"hello

> 12345 !!!! text changed .... 
> ","serverISO8601time":"2013-11-20T07:29:35.497Z","serverTime":1384932575.496999979}
>
> And put it using the update handler.
>
>    curl -s -X PUT 
> 'http://localhost:5984/i7rmdb/_design/compnbd/_update/timestamp/testid' -d 
> @/tmp/2.json
>
> Notice the text did not change, just the time stamp changed.
>
>    curl -s 'http://localhost:5984/i7rmdb/testid'
> {"_id":"testid","_rev":"6-6726469319fc80710ef15d0df6dd6320","type":"profile","text":"hello123","serverISO8601time":"2013-11-20T07:31:58.351Z","serverTime":1384932718.3510000706}
>
>
> I was expecting both text and timestamp to change.  Is that correct?
>
> Thanks
>
>
> On 11/20/2013 01:38 AM, Stanley Iriele wrote:
>> Are you asking how to update a document with an update handler? Like...what
>> the  pattern looks like?
>> On Nov 19, 2013 10:31 PM, "Alexander Shorin"<kxepal@gmail.com>  wrote:
>>
>>> The update handlers does document update already with single http
>>> request. To update document content or not is the question of function
>>> implementation.
>>> --
>>> ,,,^..^,,,
>>>
>>>
>>> On Wed, Nov 20, 2013 at 10:26 AM, Vivek Pathak<vpathak@orgmeta.com>
>>> wrote:
>>>> Hi
>>>>
>>>> I have couchdb 1.2.1 - and wanted to update document content and also
>>> run a
>>>> update handler using only one http call.
>>>>
>>>> Is it possible to do this?
>>>>
>>>> Thanks
>>>> Vivek
>>>>
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message