Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 38835 invoked from network); 8 Apr 2011 09:25:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Apr 2011 09:25:25 -0000 Received: (qmail 86139 invoked by uid 500); 8 Apr 2011 09:25:14 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 85010 invoked by uid 500); 8 Apr 2011 09:24:57 -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 84993 invoked by uid 99); 8 Apr 2011 09:24:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Apr 2011 09:24:54 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jeroentjevandijk@gmail.com designates 74.125.82.180 as permitted sender) Received: from [74.125.82.180] (HELO mail-wy0-f180.google.com) (74.125.82.180) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Apr 2011 09:24:49 +0000 Received: by wyj26 with SMTP id 26so4277054wyj.11 for ; Fri, 08 Apr 2011 02:24:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=7B8LlPTsBoOlGeA8JEG+5/UtxQKunULLIYbQ9i1Znwc=; b=Fz/ZPdU208MZT+vCV2syTMmlV5YnSA1VLVErybxxa3YqnQsdccboNCq70BgFMg86e4 Tmz+YseOCLtwS6kkvrWKtaWNiQGgsAJ1nNhR/iqDoKhHJy/YnEfOj5NhknDd8wQmgP8s BKg+pK0YfQl9jNOTmzYiZopYuOiIKm0bwKAi0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=byGAD7KZJJARwQgxNTBoCH4Hip6KoxTMcbRQXVktQOgLfPsMZ99loKCWjKjqzonXtt 9Tr2eTdAtFJhsGq3/+2OnhsCPa1eAeK9L+oJeMrujnOyHAsnszxX/LDjUbQkU3WLqMOr moI8K7+BdJafSZ6dpvEGypoAowQKN6wIdxXzM= MIME-Version: 1.0 Received: by 10.216.82.68 with SMTP id n46mr1731103wee.57.1302254667977; Fri, 08 Apr 2011 02:24:27 -0700 (PDT) Received: by 10.216.69.85 with HTTP; Fri, 8 Apr 2011 02:24:27 -0700 (PDT) Date: Fri, 8 Apr 2011 11:24:27 +0200 Message-ID: Subject: Setting default values on create server side From: Jeroen van Dijk To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=0016e6de0014e4579604a064caa2 --0016e6de0014e4579604a064caa2 Content-Type: text/plain; charset=ISO-8859-1 Hi all, I'm having troubles setting default values on new documents and have everything work like it would normally work. I have created a simple couchapp with the following rewrite rule: { "from": "api/v1/apps", "to" : "../zwapp-relax/_update/callbacks", "method": "POST" }, This will trigger the callbacks function which should set the created_at value: function(doc, req) { var newDoc = req.body; newDoc._id = req.uuid newDoc.created_at = 1; return [newDoc,"OK"]; } Everything seems to work but req.body is not parsed as JSON even though I'm setting the header 'Content-Type' to 'application/json'. req.body is just a string. When I remove the _update/callbacks part from the rewrite I get "reason":"Referer header required." Any idea of what I'm doing wrong or how I should approach setting default values server side? Thanks, Jeroen PS. The answer to this question also implies there are some difficulties doing the above: http://stackoverflow.com/questions/3009925/couchdb-automatic-timestamps --0016e6de0014e4579604a064caa2--