Try JSON.parse as in the example I sent earlier.

On Mon, Nov 18, 2013 at 4:53 PM, Hank Knight <hknight...@gmail.com> wrote:
> The problem is that the data passed via POST that is accessed with
> req.body is being added in a single string.
>
>
> This is what I get:
> "data": "{\"hello\": \"world\", \"number\": 23}"
>
>
> But I want this:
> "data": "{
>     "hello": "world",
>     "number": 23
> }
>
>
> Here is my update function:
>
> {
>    "_id": "_design/time2id",
>    "updates": {
>        "u": "function (doc, req) {var doc = new Object();doc._id =
> String(Math.round(new Date().getTime()/1000));doc.data=req.body;return
> [doc, \"Done\"];}"
>    }
> }
>
> I call it like this:
>
> curl -k -u "uiimv...@sharklasers.com:password123" -X PUT
> https://zuhqtr5.couchappy.com/testupdates/_design/time2id/_update/u/
> -d '{"hello": "world", "number": 23}' -H "Content-Type:
> application/json"
>
>
> On Mon, Nov 18, 2013 at 10:17 AM, Mike Marino <mmar...@gmail.com> wrote:
>> On Mon, Nov 18, 2013 at 3:04 PM, Hank Knight <hknight...@gmail.com> wrote:
>>> I understand that I can pass information using an update handler like this:
>>>
>>> http://127.0.0.1:5984/my_database/_design/my_designdoc/_update/in-place-query/mydocId?field=title&value=test
>>>
>>> Is there a way to use POST data with an update handler?
>>
>> Yes, you leave out the docid as in
>> http://wiki.apache.org/couchdb/Document_Update_Handlers and include
>> your data in the body of the request, if you want to use this to
>> generate a new document.  See, e.g.
>>
>> https://github.com/mgmarino/nEDM-Interface/blob/master/_default/lib/updates.js
>>
>> For an example of pulling all the data into the new document.  (It
>> uses the req.uuid as the new doc's _id, which may or may not be good
>> for your case.)

Reply via email to