Update and fetch document (for Concurrent requests)

I have a document whose DocumentId is a random number (UUID), need to update & fetch a unique record with specific status value (say NEW to INPROGRESS) with limit 1

Does Couchbase guarantee to update and retrieve one and only one unique record (for concurrent requests)?

UPDATE bucket SET status = ‘INPROGRESS’ where status = ‘NEW’ limit 1 RETURNING *

Return document key

UPDATE bucket SET status = ‘INPROGRESS’ where status = ‘NEW’ limit 1 RETURNING META().id;

Returns document and document key

UPDATE bucket AS d SET d.status = ‘INPROGRESS’ where d.status = ‘NEW’ limit 1 RETURNING d, META().id;

thanks @vsr1 but my question was on the concurrency part, can 2 threads get a handle on the same document with the above update query?

UPDATE requires fetch the document, as part of fetch it also gets CAS value and same CAS value is passed it back while updating document. If the values are different the update will raise error. cc @keshav_m

1 Like

That’s correct.
See the slide #21 to see how the update happens in Couchbase.

1 Like