couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <>
Subject [Couchdb Wiki] Update of "Document_Update_Handlers" by SimonDeBoer
Date Sun, 06 May 2012 19:27:53 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The "Document_Update_Handlers" page has been changed by SimonDeBoer:

Provide a hint on how to return the document that has been changed by this update handler.

  The handler function takes the most recent version of the document from the database and
the http request environment as parameters. It returns a two-element array: the first element
is the (updated or new) document, which is committed to the database. If the first element
is null no document will be committed to the database. If you are updating an existing, it
should already have an `_id` set, and if you are creating a new document, make sure to set
its `_id` to something, either generated based on the input or the `req.uuid` provided. The
second element is the response that will be sent back to the caller.
+ If you want the client to get the changed document (without an additional request) you can
return it as the second element of the return array, but you need to turn it into a string
+ {{{#!highlight javascript
+ {
+   updates: {
+     "in-place": "function (doc, req) {
+       doc.field = req.form.field.new_value;
+       return [doc, toJSON(doc)];
+     }"
+   }
+ }
+ }}}
+ '''Note''' The document returned in this manner will have the "old" _rev, see the response
section for how retrieve the new/current _rev.
  == Request ==
  The request parameter will look something like this for a update function designed to create
a new document:

View raw message