couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From J Chris Anderson <jch...@gmail.com>
Subject Re: Default values via _updates function
Date Tue, 02 Mar 2010 18:40:30 GMT

On Mar 2, 2010, at 10:37 AM, Jim Garvin wrote:

> I tried building from the *trunk* branch on the git mirror, specifically:
> 
> commit e13a88b46cfad2603c636cf5781469f25e9d365f
> Author: Jan Lehnardt <jan@apache.org>
> Date:   Mon Mar 1 19:46:19 2010 +0000
> 
>    Add RC note
> 
> And I got stuck with a completely new issue: Trying to create/save a
> document results in the "attempted upload of invalid JSON" error every time.
> 

hmm. Might be worth investigating your toolchain. Trunk is very stable right now (1.0 release
candidate) so if it's not working for you, that's a sign of something wrong on your end. (I
hope!)

Are the Futon tests passing on trunk for you?

Chris

> [error] [<0.5552.0>] attempted upload of invalid JSON
> {"_id":"c21df46f6ad441613897517c085114a6","_rev":"1-c9a66d15ed47ea129687e645ae3ce9d2","service":"test","body":"foo","created_at":"2010-03-01
> 09:52:32 -0500"}
> 
> So I'm about to roll back to 0.10.1 and try just applying that simple patch
> you suggested.
> 
> Fingers crossed.
> 
> Thanks,
> Jim
> 
> On Tue, Mar 2, 2010 at 12:05 PM, J Chris Anderson <jchris@gmail.com> wrote:
> 
>> 
>> On Mar 2, 2010, at 6:44 AM, Jim Garvin wrote:
>> 
>>> *Chris,*
>>> 
>>> Thanks for the response.
>>> 
>>> $ couchdb -V
>>> couchdb - Apache CouchDB 0.10.1
>>> 
>>> Judging by the CouchDB downloads
>>> page<http://couchdb.apache.org/downloads.html>,
>>> I'm on the latest stable release.  I was trying to get a sense of how far
>>> off 0.11 is, so I referred to the road
>>> map<http://couchdb.apache.org/roadmap.html> which
>>> looks like it might be out of date, and then to the JIRA
>>> issues<
>> https://issues.apache.org/jira/secure/IssueNavigator.jspa?reset=true&mode=hide&sorter/order=DESC&sorter/field=priority&resolution=-1&pid=12310780&fixfor=12313841
>>> 
>>> for
>>> 0.11, which didn't really help either.
>>> 
>>> Is CouchDB a project where it would be ill-advised to run on "edge" to
>> get
>>> some 0.11 features early?  I'll try just updating SpiderMonkey, as you
>>> suggested, first.
>> 
>> You could also try applying this 1 line patch:
>> 
>> 
>> http://github.com/apache/couchdb/commit/82ff1a2b0a15dbe181221173f3013befab68f499
>> 
>> If you are running from a release package and not source, you'll be editing
>> the file
>> 
>> /usr/local/share/couchdb/server/main.js
>> 
>> (you can tell you're in the right place because it'll say "do not edit this
>> file by hand" at the top. Don't worry about that, it's just warning that
>> your changes will be blown away by future couchdb installs. (which will have
>> the patch)
>> 
>> Let us know how it goes.
>> 
>> Chris
>> 
>>> 
>>> Thanks much.
>>> 
>>> *Mario*,
>>> 
>>> Also, thanks for the response.  As a shot in the dark, I had tried
>> parseJSON
>>> first to no avail.
>>> 
>>> Thanks again to both,
>>> Jim
>>> 
>>> 
>>> On Mon, Mar 1, 2010 at 6:06 PM, Mario Scheliga <mario@sourcegarden.de
>>> wrote:
>>> 
>>>> Hi Jim,
>>>> 
>>>> forget my last answer... sorry just grepped the source.... i think chris
>> is
>>>> right!
>>>> 
>>>> greetz
>>>> 
>>>> mario
>>>> 
>>>> Am 01.03.2010 um 23:53 schrieb Jim Garvin:
>>>> 
>>>> 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
>>>>> 
>>>> 
>>>> 
>>>> --
>>>> Sourcegarden GmbH HR: B-104357
>>>> Steuernummer: 37/167/21214 USt-ID: DE814784953
>>>> Geschaeftsfuehrer: Mario Scheliga, Rene Otto
>>>> Bank: Deutsche Bank, BLZ: 10070024, KTO: 0810929
>>>> Schoenhauser Allee 51, 10437 Berlin
>>>> 
>>>> 
>> 
>> 


Mime
View raw message