couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hank Knight <>
Subject Re: CouchDB: POST Data with Update Handler
Date Mon, 18 Nov 2013 15:53:13 GMT
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));;return
[doc, \"Done\"];}"

I call it like this:

curl -k -u "" -X PUT
-d '{"hello": "world", "number": 23}' -H "Content-Type:

On Mon, Nov 18, 2013 at 10:17 AM, Mike Marino <> wrote:
> On Mon, Nov 18, 2013 at 3:04 PM, Hank Knight <> wrote:
>> I understand that I can pass information using an update handler like this:
>> Is there a way to use POST data with an update handler?
> Yes, you leave out the docid as in
> and include
> your data in the body of the request, if you want to use this to
> generate a new document.  See, e.g.
> 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.)

View raw message