2

I have a CouchDB update handler and would like it to return a response similar to a regular document PUT or POST. So something along the lines of the following on a successful update.

{"ok": true, "id": "some_doc_id", "rev": "1-cc44942419c99df052314874d120e316"}

The problem is that in the update handler Javascript code I only have access to the current revision. I need the response to return the version after the update occurs. In this case it would be revision 2.

Can I somehow get access to the new revision in my update handler?

David V
  • 11,531
  • 5
  • 42
  • 66

2 Answers2

6

There is a response header that gets set: X-Couch-Update-NewRev which should have the new revision of the doc.

See some discussion about it here: https://issues.apache.org/jira/browse/COUCHDB-1298

Ryan Ramage
  • 2,606
  • 18
  • 17
0

No, because the update doesn't happen until after your update handler code has completed. You don't even know if your update will succeed (it might fail with a conflict if the document had been updated since the start of your update handler, for example).

Robert Newson
  • 4,631
  • 20
  • 18
  • The reason I can't access it directly in the update handler makes sense. I see that when an update error occurs, Couch returns its own error response. Is there a default success response for update handlers which might have revision information? – David V Dec 30 '11 at 19:52
  • Yes, the X-Couch-Update-NewRev response header contains the new revision. – Robert Newson Dec 30 '11 at 20:45