To use the existing doc's attributes, and update it in one request,
you'll need to PUT to the _update handler:
/<database>/_design/<design>/_update/<function>/<docid>
—Zach
On Mon, Dec 20, 2010 at 6:39 AM, He Shiming <heshiming@gmail.com> wrote:
> Dear CouchDB Community,
>
> I'm reading http://wiki.apache.org/couchdb/Document_Update_Handlers
> and I've got couple of questions.
>
> 1. I'm in need of updating documents without a prior readout to
> determine its content and revisions. The task itself is similar to
> UPDATE user SET password='x' WHERE user='id'; . I'm wondering if
> update handlers are designed for this purpose?
>
> 2. I've got a update handler like this:
> function(doc,req){
> if (!doc)
> return [null, 'fail-no-doc'];
> if (!req.query.id)
> return [null,'fail-no-id'];
> if (req.password)
> doc.password = req.password;
> return [doc,'success'];
> }
>
> I tried to call it this way: curl -d "id=docid&password=x"
> http://localhost:5984/db/_design/user/_update/update_user . It always
> return 'fail-no-doc'. I'm trying to use POST, and the wiki didn't
> mention anything about how to set document id via POST parameter. How
> do I manage to get this work, or should I just stick with PUT and send
> parameters using URL?
>
> Thanks!
> --
> Best regards,
> He Shiming
>
|