incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <rnew...@apache.org>
Subject Re: Trouble adding update function
Date Fri, 26 Jul 2013 18:36:19 GMT
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