incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Garvin <...@thegarvin.com>
Subject Default values via _updates function
Date Mon, 01 Mar 2010 22:53:46 GMT
Hi All,

I'm trying to do server-side created_at timestamps via CouchDB's _updates
features, but I'm having trouble creating a new document out of the JSON
passed in the request body.  My app doesn't allow updates to existing
documents, only "inserts".  Here's the very simple _updates function:

function(doc, req) {
  var newDoc = JSON.parse(req.body);
  newDoc.created_at = new Date();
  return [newDoc, "FML"];
}

When I POST a document to the appropriate _updates URL, I get an error in
the log telling me that JSON is not defined:

[info] [<0.30422.5>] OS Process :: function raised error: ReferenceError:
JSON is not defined

I wasn't able to find much reference on the web aside from:
http://wiki.apache.org/couchdb/How_to_intercept_document_updates_and_perform_additional_server-side_processing
http://www.mikealrogers.com/archives/737

In the mikealrogers.com post, the author uses JSON in his function, but
obviously I'm having problems with that approach.  Does anyone know what a
proper way to convert the body of the POST a javascript object would be?
 (avoiding eval()).  Also, taking a step back, is this the right approach
for setting default values on a new document in CouchDB?

Thanks,
Jim

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