couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Josh803316 <josh803...@gmail.com>
Subject Re: how should I handle JSON parsing in update handler
Date Sat, 18 Dec 2010 19:18:43 GMT
Yes, that worked thank you

function(doc, req) { var field = req.query.field;var value =
req.query.value;doc[field] = value;return[doc,JSON.stringify({ 'status':
value})];}

On Sat, Dec 18, 2010 at 1:11 PM, Paul Davis <paul.joseph.davis@gmail.com>wrote:

> Oh right.
>
> Then it'd be:
>
>    return [doc, JSON.stringify({"STATUS": "message"})];
>
> Or w/e
>
> On Sat, Dec 18, 2010 at 2:09 PM, Josh803316 <josh803316@gmail.com> wrote:
> > http://wiki.apache.org/couchdb/Document_Update_Handlers
> >
> > <http://wiki.apache.org/couchdb/Document_Update_Handlers>I see a value
> > returned as well in the examples
> >
> > On Sat, Dec 18, 2010 at 12:50 PM, Paul Davis <
> paul.joseph.davis@gmail.com>wrote:
> >
> >> On Sat, Dec 18, 2010 at 1:48 PM, Josh803316 <josh803316@gmail.com>
> wrote:
> >> > The reason I ask is because of this, I have an update function that
> >> updates
> >> > the 'status' key of a document.......but when I send the request
> (command
> >> > line curl) I keep getting errors on the server return.
> >> >
> >> > curl -X PUT
> >> >
> >>
> http://localhost:5984/workers/_design/tasc/_update/status/94472998f519050f3a2271888d137ed7\?field=status\&value=RUNNING
> >> <
> >>
> http://localhost:5984/workers/_design/tasc/_update/status/94472998f519050f3a2271888d137ed7%5C?field=status%5C&value=RUNNING
> >> >
> >> >
> >> > {"error":"external_response_error","reason":"Invalid data from
> external
> >> > server: {<<\"status\">>,<<\"RUNNING\">>}"}
> >> >
> >> > Here is my update function......do I need to JSON Encode the returned
> >> object
> >> > message?
> >> > {
> >> >   "status": "function(doc, req) {
> >> >                    var field = req.query.field;
> >> >                    var value = req.query.value;
> >> >                    doc[field] = value;
> >> >                    return[doc,{"status":value}];
> >> >    }",
> >> > }
> >>
> >> Pretty sure its supposed to be "return doc;"
> >>
> >> >
> >> >> On Sat, Dec 18, 2010 at 12:40 PM, Josh803316 <josh803316@gmail.com>
> >> wrote:
> >> >>
> >> >>> Oops I forgot to ask how I encode as well, is it JSON.encode?
> >> >>>
> >> >>>
> >> >>> On Mon, Dec 13, 2010 at 10:24 AM, Zachary Zolton <
> >> >>> zachary.zolton@gmail.com> wrote:
> >> >>>
> >> >>>> You can use the global JSON object for this:
> >> >>>>
> >> >>>> function(doc, req) {
> >> >>>>     var active_test = JSON.parse(req.body);
> >> >>>>
> >> >>>>     doc['active_test'] = active_test;
> >> >>>>     return [doc, req.body];
> >> >>>>    }
> >> >>>>
> >> >>>> Cheers,
> >> >>>> Zach
> >> >>>>
> >> >>>> On Sat, Dec 11, 2010 at 1:06 PM, Josh803316 <josh803316@gmail.com>
> >> >>>> wrote:
> >> >>>> > If I send a json string to my update handler as part of
req.body
> >> what
> >> >>>> is the
> >> >>>> > best way to convert it to a JSON object?
> >> >>>> >
> >> >>>> > Do the CouchDb js libraries already include a built in
JSON
> parser
> >> or
> >> >>>> do I
> >> >>>> > have to use eval?
> >> >>>> >
> >> >>>> > "active_test" : function(doc, req) {
> >> >>>> >      var active_test = eval('(' + req.body + ')');
> >> >>>> >
> >> >>>> >      doc['active_test'] = active_test;
> >> >>>> >      return [doc, req.body];
> >> >>>> >     }
> >> >>>> >
> >> >>>>
> >> >>>
> >> >>>
> >> >>
> >> >
> >>
> >
>

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