couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeroen van Dijk <jeroentjevand...@gmail.com>
Subject Setting default values on create server side
Date Fri, 08 Apr 2011 09:24:27 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message