-2

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.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
JAM
  • 740
  • 3
  • 15
  • 33
  • Pass the same _rev you got when you retrieved the document. Its purpose is to ensure that you're updating the record you retrieved. – Burak Serdar Mar 16 '20 at 19:33
  • Great, thank worked. @BurakSerdar if you post this as an answer I will accept it – JAM Mar 16 '20 at 19:34

1 Answers1

1

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.

Burak Serdar
  • 46,455
  • 3
  • 40
  • 59