Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 67223 invoked from network); 27 Apr 2010 14:54:45 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 27 Apr 2010 14:54:45 -0000 Received: (qmail 125 invoked by uid 500); 27 Apr 2010 14:54:43 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 99968 invoked by uid 500); 27 Apr 2010 14:54:43 -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 99960 invoked by uid 99); 27 Apr 2010 14:54:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Apr 2010 14:54:43 +0000 X-ASF-Spam-Status: No, hits=0.3 required=10.0 tests=AWL,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jchris@gmail.com designates 209.85.219.221 as permitted sender) Received: from [209.85.219.221] (HELO mail-ew0-f221.google.com) (209.85.219.221) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Apr 2010 14:54:36 +0000 Received: by ewy21 with SMTP id 21so3977379ewy.25 for ; Tue, 27 Apr 2010 07:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:content-type:mime-version :subject:from:in-reply-to:date:content-transfer-encoding:message-id :references:to:x-mailer; bh=CVwW2oGGiaDCZ6aV6Jr9NAX2B3XvZVTRNPcFIF85PQo=; b=KMwHu7J3yqFOOvOLCAZjyrBl1WVKUwqylZuN/2z1XTcUMMR7fkGoPtoStLK7Y1IA6q ijoH863tvTwgrPpFrvUg7r6VHngt4dfuJLm5yQ8swKMX5Fi4myRhVw/eusMDR3XtH3Wz SDWdTFIkB/S9ByoQNTCH5ohxAGOV4HTMFdL7U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; b=pYGZll9kOiriq+pPI7l7X9c6JJQAmOK2z4PcfbhS4w8evni2wTQ5eyfenNg+GGQKSQ uxbvdI+ML9s5lvDUiBcS+cAJF1aWsWWyoZ/HjZz8p6VcVVoVS/wWfcUb8vjM5hKVGEAo tVrxwgZNm0/CCbyVR3Oes36HDIqs0rOKnWDDE= Received: by 10.103.37.1 with SMTP id p1mr3272781muj.1.1272380050806; Tue, 27 Apr 2010 07:54:10 -0700 (PDT) Received: from [192.168.1.101] (c-98-248-172-14.hsd1.ca.comcast.net [98.248.172.14]) by mx.google.com with ESMTPS id 23sm22620559mum.36.2010.04.27.07.54.08 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 27 Apr 2010 07:54:09 -0700 (PDT) Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Apple Message framework v1078) Subject: Re: How to change JSON before storing From: J Chris Anderson In-Reply-To: Date: Tue, 27 Apr 2010 07:54:05 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: References: <28B4793B-46E8-43B2-82BF-BDCD3BCDAD1E@googlemail.com> To: user@couchdb.apache.org X-Mailer: Apple Mail (2.1078) On Apr 27, 2010, at 7:48 AM, Andreas K=F6berle wrote: > I don't get it. Logging req and doc shows me that doc is null, but > req.body has the json: >=20 yes. that is the idea. CouchDB doesn't know if the request is JSON or CSV or whatever, so it = doesn't try to parse it for you. Since you don't have a doc with that id = already, doc is null. So you need to do something like: function(doc, req){ var newDoc =3D JSON.parse(req.body); newDoc.date =3D new Date();=20 return [newDoc, "yay it worked!"]; } > 1> [info] [<0.930.0>] OS Process :: req.info: [object Object] > 1> [info] [<0.930.0>] OS Process :: req.verb: POST > 1> [info] [<0.930.0>] OS Process :: req.path: > yslow,_design,yslow,_update,addDate > 1> [info] [<0.930.0>] OS Process :: req.query: [object Object] > 1> [info] [<0.930.0>] OS Process :: req.headers: [object Object] > 1> [info] [<0.930.0>] OS Process :: req.body: > = {"w":50433,"o":94,"u":"http%3A%2F%2Fwww.google.de%2F","r":6,"s":"","i":"yd= efault","lt":401,"comps": > = [{"type":"doc","url":"http%3A%2F%2Fwww.google.de%2F","size":11944,"resp":5= 3,"gzip":"4730","cr":481},{"type":"js","url":"http%3A%2F%2Fwww.google.d > = e%2Fextern_js%2Ff%2FCgJkZRICZGUrMAo4Y0AdLCswDjgNLCswFjgXLCswFzgGLCswGDgFLC= swGTgcLCswHTgrLCswITg1QAEsKzAlOMqIASwrMCY4CiwrMCc4BCwrMCo4BCwrMCs4DCwrM > = Dw4AiwrMEA4DywrMEU4ASwrME44BCwrMFE4ACyAAg0%2F_urb4V0rNT4.js","size":73479,= "resp":4,"gzip":"27110","expires":"2011/4/26"},{"type":"js","url":"http > = %3A%2F%2Fwww.google.de%2Fextern_chrome%2Febbd8e4827c4c9bc.js","size":13362= ,"resp":6,"gzip":"3816","expires":"2011/4/26"},{"type":"image","url":"h > = ttp%3A%2F%2Fwww.google.de%2Fintl%2Fde_de%2Fimages%2Flogo.gif","size":9121,= "resp":9,"expires":"2010/4/27"},{"type":"image","url":"http%3A%2F%2Fwww > = .google.de%2Fimages%2Fnav_logo8.png","size":5656,"resp":16,"expires":"2010= /4/27"},{"type":"doc","url":"http%3A%2F%2Fclients1.google.de%2Fgenerate > _204","size":0,"resp":28,"cr":481}]} > 1> [info] [<0.930.0>] OS Process :: req.form: [object Object] > 1> [info] [<0.930.0>] OS Process :: req.cookie: [object Object] > 1> [info] [<0.930.0>] OS Process :: req.userCtx: [object Object] > 1> [info] [<0.930.0>] OS Process :: doc: null >=20 >=20 >=20 > On 27 April 2010 15:58, Andreas K=F6berle wrote: >> Ok there was an error in my design doc now it looks like: >>=20 >> { >> "_id": "_design/yslow", >> "_rev": "12-ad0d504e48808ef5643545e3817a62f8", >> "updates": { >> "addDate": "function(doc, req){doc.date =3D new Date(); = return[doc,req]}" >> } >> } >>=20 >> And I got another error: JavaScript function raised error: TypeError: >> doc is null. Normal saving the json in http://exeter:5984/yslow works >> well by the way. >>=20 >> On 27 April 2010 15:17, Andreas K=F6berle wrote: >>> Mhmm it seems that POST work, but now I get another quirk. >>>=20 >>> this is my design doc: >>> { >>> "_id": "_design/yslow", >>> "_rev": "9-a4ece33bca6f678cf1752907bfe8596c", >>> "updates": "{'addDate' : 'function(doc, req){doc.date =3D new = Date(); >>> return[doc,req]}'}" >>> } >>>=20 >>> this is my url: >>> http://exeter:5984/yslow/_design/yslow/_update/addDate >>>=20 >>> this is the json that YSLOW sends: >>>=20 >>> var a =3D = {"w":41480,"o":93,"u":"http%3A%2F%2Fwww.google.com%2Fsearch%3Fie%3DUTF-8%2= 6oe%3DUTF-8%26sourceid%3Dnavclient%26gfns%3D1%26q%3Dyslow%2Bbeacon%2Bcouch= db","r":6,"s":"","i":"ydefault","lt":582,"comps":[ >>> { >>> "type":"doc", >>> = "url":"http%3A%2F%2Fwww.google.com%2Fsearch%3Fie%3DUTF-8%26oe%3DUTF-8%26so= urceid%3Dnavclient%26gfns%3D1%26q%3Dyslow%2Bbeacon%2Bcouchdb", >>> "size":31534, >>> "resp":226, >>> "gzip":8407, >>> "cr":481 >>> }, >>> { >>> "type":"js", >>> = "url":"http%3A%2F%2Fwww.google.com%2Fextern_js%2Ff%2FCgJkZSswCjhjQB0sKzAOO= A0sKzAWOBcsKzAXOAYsKzAYOAUsKzAZOBwsKzAhODVAASwrMCU4yogBLCswJjgKLCswJzgELCs= wKjgELCswKzgMLCswPDgCLCswQDgPLCswRTgBLCswTjgELCswUTgALIACDQ%2FKQlSo2GWluY.= js", >>> "size":57272, >>> "resp":24, >>> "gzip":"21189", >>> "expires":"2011/4/26" >>> }, >>> { >>> "type":"cssimage", >>> = "url":"http%3A%2F%2Fwww.google.com%2Fimages%2Fnav_logo8.png", >>> "size":5656, >>> "resp":24, >>> "expires":"2010/4/27" >>> }, >>> { >>> "type":"image", >>> = "url":"http%3A%2F%2Fwww.google.com%2Fimages%2Ficons%2Fsearch-16.gif", >>> "size":1005, >>> "resp":23, >>> "expires":"2010/4/27" >>> }, >>> { >>> "type":"image", >>> = "url":"http%3A%2F%2Fwww.google.com%2Fimages%2Fswxa.gif", >>> "size":5223, >>> "resp":22, >>> "expires":"2010/4/27" >>> }, >>> { >>> "type":"doc", >>> = "url":"http%3A%2F%2Fclients1.google.com%2Fgenerate_204", >>> "size":0, >>> "resp":null >>> } >>> ]} >>>=20 >>> and this is the error I've got: >>>=20 >>> 1> [debug] [<0.11411.0>] OAuth Params: [] >>> 1> [debug] [<0.11411.0>] Minor error in HTTP request: = {not_found,json_mismatch} >>> 1> [debug] [<0.11411.0>] Stacktrace: = [{couch_util,get_nested_json_value,2}, >>> {couch_httpd_show,handle_doc_update_req,2}, >>> {couch_httpd_db,do_db_req,2}, >>> {couch_httpd,handle_request,5}, >>> {mochiweb_http,headers,5}, >>> {proc_lib,init_p_do_apply,3}] >>> 1> [debug] [<0.11411.0>] httpd 404 error response: >>> {"error":"not_found","reason":"json_mismatch"} >>>=20 >>>=20 >>> On 27 April 2010 14:48, Adam Kocoloski wrote: >>>> No, validation functions cannot modify documents. The usual reason = given is that they run during replication as well as during client = updates. >>>>=20 >>>> Adam >>>>=20 >>>> On Apr 27, 2010, at 8:40 AM, Andreas K=F6berle wrote: >>>>=20 >>>>> Unfortunately _updates doesn't work for me cause YSLOW send with = POST >>>>> and I get a "Only DELETE,GET,HEAD,PUT allowed" error. Could I use >>>>> validate_doc_update instead? >>>>>=20 >>>>>=20 >>>>> On 27 April 2010 14:12, Adam Kocoloski = wrote: >>>>>> That's correct, Simon, _update handlers don't work with = _bulk_docs today. Best, >>>>>>=20 >>>>>> Adam >>>>>>=20 >>>>>> On Apr 27, 2010, at 8:07 AM, Simon Metson wrote: >>>>>>=20 >>>>>>> Hi, >>>>>>> Is it possible to apply an update function to a bulk = insert? =46rom reading that page it sounds like not... >>>>>>> Cheers >>>>>>> Simon >>>>>>>=20 >>>>>>> On 27 Apr 2010, at 11:05, Sebastian Cohnen wrote: >>>>>>>=20 >>>>>>>> The answer is yes, to make it short :) >>>>>>>>=20 >>>>>>>> http://wiki.apache.org/couchdb/Document_Update_Handlers >>>>>>>>=20 >>>>>>>>=20 >>>>>>>> On 27.04.2010, at 11:56, Andreas K=F6berle wrote: >>>>>>>>=20 >>>>>>>>> Is there a way to add data to a JSON Object with couchdb, = before >>>>>>>>> storing it. I've got data direct from YSlow firefox extension = but >>>>>>>>> unfortunately without a timestamp. >>>>>>>>=20 >>>>>>>=20 >>>>>>=20 >>>>>>=20 >>>>=20 >>>>=20 >>>=20 >>=20