Delete Document in CouchDB

CouchDB Delete Document

Using Fauxton:

  • Open the following URL: http://127.0.0.1:5984/_utils/
  • Select the database that contains the document to delete.
  • Select the document to delete.
  • Click on the delete icon.
  • A pop-up message “Are you sure you want to delete this doc?” will be displayed.
  • Click on the OK button.
  • The selected document is thus deleted.

 

Using cURL utility:

Syntax:

curl -H 'Content-Type: application/json' \

-X DELETE http://127.0.0.1:5984/database_name/database_id?_rev

 

Example:

Retrieve the latest revision id of the document to be deleted.

curl -X GET http://127.0.0.1:5984/company/100

Use the revision id in the below command.

curl -H 'Content-Type: application/json' \

-X DELETE http://127.0.0.1:5984/company/100 ?rev=2-5fef7ea4661b53c017e123456e4f2beb

 

Explanation:

The response will contain 3 fields:

  • “ok”: It is used to specify that the operation is successful.
  • “id”: It is used to store the id of the document.
  • “rev”: It is used to specify the revision id. A _rev value is generated by CouchDB, every time when a document is revised (updated or modified).

 

Verification:

Verify the document deleted using the below command:

curl -X GET http://127.0.0.1:5984/database_name/ID   

 

Please follow and like us:
Content Protection by DMCA.com