incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hank Knight <hknight...@gmail.com>
Subject Re: Trouble adding update function
Date Fri, 26 Jul 2013 19:29:01 GMT
Even when I use the code posted in the documentation I get the same error:
http://pastebin.com/k0F4F7h0

I am still at a loss as to how to add a simple update handler.


On Fri, Jul 26, 2013 at 3:36 PM, Robert Newson <rnewson@apache.org> wrote:
> Use couchapp or kanso or situp or anything to help you form a properly
> formed design document.
>
> Short version: You are posting a javascript function where a JSON
> document is needed;
>
> http://wiki.apache.org/couchdb/Document_Update_Handlers
>
> On 26 July 2013 19:32, Hank Knight <hknight555@gmail.com> wrote:
>> I am trying to add a simple update function.  Steps 1 and 2 work by I
>> get an error with step 3:
>> {"error":"bad_request","reason":"invalid_json"}
>>
>> Of course I am trying to add a JavaScript function, not JSON.
>>
>> What am I doing wrong?  Am I missing a step?
>>
>> ### Step 1: Create a file named 'update.js' ###
>>
>> function(doc, req){
>>     if (!doc){
>>         if ('id' in req){
>>             // create new document
>>             return [{'_id': req['id']}, 'New World']
>>         }
>>         // change nothing in database
>>         return [null, 'Empty World']
>>     }
>>     doc['world'] = 'hello';
>>     doc['edited_by'] = req['userCtx']['name']
>>     return [doc, 'Edited World!']
>> }
>>
>> ### Step 2: Create a database ###
>> curl -X PUT http://127.0.0.1:5984/hello
>>
>> ### Step 3: Add the Update Function ###
>>
>> curl -X PUT http://127.0.0.1:5984/hello/_design/autotime --data-binary
>> @update.js

Mime
View raw message