incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From J Chris Anderson <>
Subject Re: Default values via _updates function
Date Mon, 01 Mar 2010 22:57:41 GMT

On Mar 1, 2010, at 2:53 PM, Jim Garvin wrote:

> 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

What is your CouchDB version? On certain versions of CouchDB trunk (with older versions of
Spidermonkey) JSON is not available in the sandbox. This is fixed in the 0.11 release. Or
you can upgrade to a newer spidermonkey and I think you'll get the native JSON object.


> I wasn't able to find much reference on the web aside from:
> In the 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

View raw message