incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hank Knight <hknight...@gmail.com>
Subject Trouble adding update function
Date Fri, 26 Jul 2013 18:32:22 GMT
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