According to CouchDB and Cloudant documentation, to update an existing document, you issue a PUT request. In this case, the JSON body must contain a _rev
property. If this property/field is not provided, the update will fail with error Document update conflict. Trying to update an existing document with an incorrect _rev will cause failure too.
However, there isn't enough documentation on how to generate the _rev field when making the update request. The _rev field returned by getting the document would be something like 1-c8c95e64d4372b0c12c740a40109b87g
. In my PUT call, I have tried setting this to 2-c8c95e64d4372b0c12c740a40109b87g
, 2
, and other strings but nothing works. How do I actually generate a new _rev property for my request?
I am using Go.
Pass the same _rev
value you got when you retrieved the document. The purpose of the _rev
is to make sure that when you update a document, it is still the same document you retrieved.