From user-return-10292-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Tue Apr 27 14:49:14 2010 Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 65484 invoked from network); 27 Apr 2010 14:49:14 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 27 Apr 2010 14:49:14 -0000 Received: (qmail 88526 invoked by uid 500); 27 Apr 2010 14:49:13 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 88490 invoked by uid 500); 27 Apr 2010 14:49:13 -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 88482 invoked by uid 99); 27 Apr 2010 14:49:13 -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:49:13 +0000 X-ASF-Spam-Status: No, hits=0.2 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 koeberle@gmail.com designates 209.85.218.221 as permitted sender) Received: from [209.85.218.221] (HELO mail-bw0-f221.google.com) (209.85.218.221) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Apr 2010 14:49:06 +0000 Received: by bwz21 with SMTP id 21so12423451bwz.35 for ; Tue, 27 Apr 2010 07:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=X+J2gmTYYmiKo/J8bZH0yrORVC4lhU/NWeAnkZmqYWk=; b=e+WbZA+pwhY1XOWiyrKDMN0T7d7gF8D+iW8RGAsYVvalXPdFeu7Wu3ExBD3DjWJXtB UmT7YpzmYBUC7I0TlLGbTsSwKbj9ObURdtSQxW0iylFbu1/9iQVhelbvdYBl2XqqaRqg 3JKidVGKklXr08Aupha/kKTIgt7dp9RTWsGsE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=nq8OHMsLylC59HyyOB8mzBMyH/aAF7PeHdplRJ0J480WuJHWoRU35CgsH0uQN1Zx9g yvqgd6O2W43l5tcEfgxlvAp8DabXELsYxOme08aFOmXUTPe5nirCBaRRCtwqYZqZqyyH wKpnJRXgr5AhFIkm4Sw4byUR6V2IHRm83dtK0= MIME-Version: 1.0 Received: by 10.204.163.143 with SMTP id a15mr3738976bky.128.1272379724067; Tue, 27 Apr 2010 07:48:44 -0700 (PDT) Received: by 10.204.54.208 with HTTP; Tue, 27 Apr 2010 07:48:43 -0700 (PDT) In-Reply-To: References: <28B4793B-46E8-43B2-82BF-BDCD3BCDAD1E@googlemail.com> Date: Tue, 27 Apr 2010 16:48:43 +0200 Message-ID: Subject: Re: How to change JSON before storing From: =?ISO-8859-1?Q?Andreas_K=F6berle?= To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I don't get it. Logging req and doc shows me that doc is null, but req.body has the json: 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":"yde= fault","lt":401,"comps": [{"type":"doc","url":"http%3A%2F%2Fwww.google.de%2F","size":11944,"resp":53= ,"gzip":"4730","cr":481},{"type":"js","url":"http%3A%2F%2Fwww.google.d e%2Fextern_js%2Ff%2FCgJkZRICZGUrMAo4Y0AdLCswDjgNLCswFjgXLCswFzgGLCswGDgFLCs= wGTgcLCswHTgrLCswITg1QAEsKzAlOMqIASwrMCY4CiwrMCc4BCwrMCo4BCwrMCs4DCwrM 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 On 27 April 2010 15:58, Andreas K=F6berle wrote: > Ok there was an error in my design doc now it looks like: > > { > =A0 "_id": "_design/yslow", > =A0 "_rev": "12-ad0d504e48808ef5643545e3817a62f8", > =A0 "updates": { > =A0 =A0 =A0 "addDate": "function(doc, req){doc.date =3D new Date(); retur= n[doc,req]}" > =A0 } > } > > 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. > > On 27 April 2010 15:17, Andreas K=F6berle wrote: >> Mhmm it seems that POST work, but now I get another quirk. >> >> this is my design doc: >> { >> =A0 "_id": "_design/yslow", >> =A0 "_rev": "9-a4ece33bca6f678cf1752907bfe8596c", >> =A0 "updates": "{'addDate' : 'function(doc, req){doc.date =3D new Date()= ; >> return[doc,req]}'}" >> } >> >> this is my url: >> http://exeter:5984/yslow/_design/yslow/_update/addDate >> >> this is the json that YSLOW sends: >> >> var a =3D {"w":41480,"o":93,"u":"http%3A%2F%2Fwww.google.com%2Fsearch%3F= ie%3DUTF-8%26oe%3DUTF-8%26sourceid%3Dnavclient%26gfns%3D1%26q%3Dyslow%2Bbea= con%2Bcouchdb","r":6,"s":"","i":"ydefault","lt":582,"comps":[ >> =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"type":"doc", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"url":"http%3A%2F%2Fwww.google.com%2Fsear= ch%3Fie%3DUTF-8%26oe%3DUTF-8%26sourceid%3Dnavclient%26gfns%3D1%26q%3Dyslow%= 2Bbeacon%2Bcouchdb", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"size":31534, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"resp":226, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"gzip":8407, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"cr":481 >> =A0 =A0 =A0 =A0}, >> =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"type":"js", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"url":"http%3A%2F%2Fwww.google.com%2Fexte= rn_js%2Ff%2FCgJkZSswCjhjQB0sKzAOOA0sKzAWOBcsKzAXOAYsKzAYOAUsKzAZOBwsKzAhODV= AASwrMCU4yogBLCswJjgKLCswJzgELCswKjgELCswKzgMLCswPDgCLCswQDgPLCswRTgBLCswTj= gELCswUTgALIACDQ%2FKQlSo2GWluY.js", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"size":57272, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"resp":24, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"gzip":"21189", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"expires":"2011/4/26" >> =A0 =A0 =A0 =A0}, >> =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"type":"cssimage", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"url":"http%3A%2F%2Fwww.google.com%2Fimag= es%2Fnav_logo8.png", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"size":5656, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"resp":24, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"expires":"2010/4/27" >> =A0 =A0 =A0 =A0}, >> =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"type":"image", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"url":"http%3A%2F%2Fwww.google.com%2Fimag= es%2Ficons%2Fsearch-16.gif", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"size":1005, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"resp":23, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"expires":"2010/4/27" >> =A0 =A0 =A0 =A0}, >> =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"type":"image", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"url":"http%3A%2F%2Fwww.google.com%2Fimag= es%2Fswxa.gif", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"size":5223, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"resp":22, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"expires":"2010/4/27" >> =A0 =A0 =A0 =A0}, >> =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"type":"doc", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"url":"http%3A%2F%2Fclients1.google.com%2= Fgenerate_204", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"size":0, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"resp":null >> =A0 =A0 =A0 =A0} >> ]} >> >> and this is the error I've got: >> >> 1> [debug] [<0.11411.0>] OAuth Params: [] >> 1> [debug] [<0.11411.0>] Minor error in HTTP request: {not_found,json_mi= smatch} >> 1> [debug] [<0.11411.0>] Stacktrace: [{couch_util,get_nested_json_value,= 2}, >> =A0 =A0 =A0 =A0 =A0 =A0 {couch_httpd_show,handle_doc_update_req,2}, >> =A0 =A0 =A0 =A0 =A0 =A0 {couch_httpd_db,do_db_req,2}, >> =A0 =A0 =A0 =A0 =A0 =A0 {couch_httpd,handle_request,5}, >> =A0 =A0 =A0 =A0 =A0 =A0 {mochiweb_http,headers,5}, >> =A0 =A0 =A0 =A0 =A0 =A0 {proc_lib,init_p_do_apply,3}] >> 1> [debug] [<0.11411.0>] httpd 404 error response: >> =A0{"error":"not_found","reason":"json_mismatch"} >> >> >> On 27 April 2010 14:48, Adam Kocoloski wrote: >>> No, validation functions cannot modify documents. =A0The usual reason g= iven is that they run during replication as well as during client updates. >>> >>> Adam >>> >>> On Apr 27, 2010, at 8:40 AM, Andreas K=F6berle wrote: >>> >>>> 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? >>>> >>>> >>>> On 27 April 2010 14:12, Adam Kocoloski wrote: >>>>> That's correct, Simon, _update handlers don't work with _bulk_docs to= day. =A0Best, >>>>> >>>>> Adam >>>>> >>>>> On Apr 27, 2010, at 8:07 AM, Simon Metson wrote: >>>>> >>>>>> Hi, >>>>>> =A0 =A0 =A0 Is it possible to apply an update function to a bulk ins= ert? From reading that page it sounds like not... >>>>>> Cheers >>>>>> Simon >>>>>> >>>>>> On 27 Apr 2010, at 11:05, Sebastian Cohnen wrote: >>>>>> >>>>>>> The answer is yes, to make it short :) >>>>>>> >>>>>>> http://wiki.apache.org/couchdb/Document_Update_Handlers >>>>>>> >>>>>>> >>>>>>> On 27.04.2010, at 11:56, Andreas K=F6berle wrote: >>>>>>> >>>>>>>> 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. >>>>>>> >>>>>> >>>>> >>>>> >>> >>> >> >