CouchDB - Updating A Document
CouchDB - Updating A Document
Example
Suppose there is a document with id 001 in the database named my_database. You can
delete this as shown below.
First of all, get the revision id of the document that is to be updated. You can find the _rev
of the document in the document itself, therefore get the document as shown below.
Use revision id _rev from the document to update the document. Here we are updating the
age from 23 to 24.
{ " ok " : true , " id " : " 001 " , " rev " : " 2-04d8eac1680d237ca25b68b36b8899d3 "
Verification
To verify the document, get the document again using GET request as shown below.
Note
The URL we send in the request containing the database name and the document id.
Updating an existing document is same as updating the entire document. You cannot
add a field to an existing document. You can only write an entirely new version of the
document into the database with the same document ID.
In return JSON contains the success message, the ID of the document being
updated, and the new revision information. If you want to update the new version of
the document, you have to quote this latest revision number.
Select the database in which the document to be updated exists and click it. Here we are
updating a document in the database named tutorials_point. You will get the list of
documents in the database as shown below.
Select a document that you want to update and click on it. You will get the contents of the
documents as shown below.
Here, to update the location from Delhi to Hyderabad, click on the text box, edit the field,
and click the green button to save the changes as shown below.