Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D450DC491 for ; Fri, 26 Jul 2013 18:36:22 +0000 (UTC) Received: (qmail 2449 invoked by uid 500); 26 Jul 2013 18:36:21 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 2422 invoked by uid 500); 26 Jul 2013 18:36:21 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 2412 invoked by uid 99); 26 Jul 2013 18:36:20 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Jul 2013 18:36:20 +0000 Received: from localhost (HELO mail-vc0-f177.google.com) (127.0.0.1) (smtp-auth username rnewson, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Jul 2013 18:36:20 +0000 Received: by mail-vc0-f177.google.com with SMTP id gf12so721125vcb.22 for ; Fri, 26 Jul 2013 11:36:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=bfWvlsH3XwMlhUX5RsZaejOjMiSCU9Ferkyd1Mv6PPs=; b=Z2LbpMbm+xKfAsMo2aX6p4JyqDRW+Eksidbr3Fpj5gJx/ZcVWlQiZqVD+0vJ2wbYoi KuCgshl+d13H+V4pxxAxbN1cF7mROeHEOQBhqSFham60NQgRF446zDgzyxGZ3/twymcM Xb3IeIsa32DpNwHD/jmZidcWycSKH4T5MrDglMPgXyMMCS3vpWlzIAS+wpX7keyxf9HH sNbpHBN5WBHwUGZZZnUSCMRZU3EyidQFS2KzqiFptwtpiP7z00BhUvtmWfwgKG646a59 pjihm14m8oJsgqbaP4AOdOJPUV6a5okJERv8Kr9LjAF5e458mroIfbUHwgV6iMox38AR khzg== MIME-Version: 1.0 X-Received: by 10.220.249.67 with SMTP id mj3mr4033059vcb.23.1374863779292; Fri, 26 Jul 2013 11:36:19 -0700 (PDT) Received: by 10.220.149.73 with HTTP; Fri, 26 Jul 2013 11:36:19 -0700 (PDT) In-Reply-To: References: Date: Fri, 26 Jul 2013 19:36:19 +0100 Message-ID: Subject: Re: Trouble adding update function From: Robert Newson To: "user@couchdb.apache.org" Content-Type: text/plain; charset=ISO-8859-1 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 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