An update to a couchdb document is atomic, whether done directly or via an 
update handler. An update handler can fail with a 409 just the same as a direct 
update can. The only difference between the two update methods is where the 
logic runs. The update handler is merely returning the new document to couchdb, 
the actual update occurs after the function has returned (and can fail).

B.

On 19 Jul 2012, at 22:09, Andrew Melo wrote:

> Hello all,
> 
> The documentation is a bit unclear on this, but basically I was
> wondering what sort of atomicity guarantees exist for _update
> handlers. Suppose I have documents that look like this
> 
> { 'states' : [ { 'oldstate' : 'created', 'newstate' : 'new' } ] }
> 
> And an update handler that looks like this (probably not the exactly
> right syntax)
> 
> function (doc, req) {
>  // check that the requested old state equals the previous new state
>  if doc.states[ len(doc.states) ]['newstate'] == req.query['oldstate'] {
>     // update the document, adding a new state to the end of doc.states
>  } else {
>     // barf back to the user
>  }
> }
> 
> Is there a guarantee that concurrent requests to the same instance
> can't end up with a garbled ordering of states?
> 
> Thanks,
> Andrew
> 
> -- 
> --
> Andrew Melo

Reply via email to