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 08:16:32 GMT
Ok - got it

I should have used

    var newdoc = JSON.parse(req.body) ;

I guess returning string as the first arg was somehow silently 
ignored.   Also the permissiveness of javascript allowed the rest of the 
code to run without exception

js> newdoc = "hello world" ;
"hello world"
js> var d = new Date();
js> newdoc.serverISO8601time = d.toISOString();
"2013-11-20T08:14:55.731Z"
js> newdoc.serverTime = d.getTime() / 1000 ;
1384935295.731
js> newdoc
"hello world"


Thanks


On 11/20/2013 03:10 AM, Vivek Pathak wrote:
> Ok - so we are taking about the first problem only.
>
> If I try this, then I get not update to the data at all:
>
> function(doc, req) {
>     if( doc.type == "profile" ) {
>         var newdoc = req.body ;
>         var d = new Date();
>         newdoc.serverISO8601time = d.toISOString();
>         newdoc.serverTime = d.getTime() / 1000 ;
>         log( toJSON(newdoc) ) ;
>         return [newdoc , "OK"] ;
>     }
> }
>
> What is wrong here?
>
>
>
>
> On 11/20/2013 03:04 AM, Alexander Shorin wrote:
>> On Wed, Nov 20, 2013 at 12:01 PM, Vivek Pathak <vpathak@orgmeta.com> 
>> wrote:
>>> On 11/20/2013 02:48 AM, Alexander Shorin wrote:
>>>> First problem is that your update function works with `doc` argument -
>>>> that is the stored within database document -, not that you had sent
>>>> with PUT request. To process the request payload you need to work with
>>>> req.body data, but in your case this isn't need to.
>>>>
>>>> Second is that both text and timestamp have actually changed - take a
>>>> look on them one more time (;
>>>
>>> I see "hello 123" in both the text fields.  Not sure what you see as 
>>> the
>>> change.
>> Your update function changes only serverISO8601time and serverTime
>> fields, not any others.
>>
>> -- 
>> ,,,^..^,,,
>


Mime
View raw message