CouchDB Deleting Document

You can Delete a document in CouchDB by sending an HTTP request to the server using PUT method through cURL utility.

Syntax

curl -X DELETE http : // 127.0.0.1:5984 / database-name/database id?_rev id

Example :

The database with the "contacts" contains the document with ID johndoe.
First you have to get the revision ID of the document which is to be deleted. If you don't know _rev, you can find yourself in the document using the command below. Now after getting the revision ID, use _rev from the document to delete the document. Now, we are deleting the document.

Find revision ID
$ curl -X GET http://127.0.0.1:5984/contacts/johndoe
{
"_id" : "johndoe",
"_rev" : "2-04d8eac1680d237ca25b68b36b8899d3 " ,
"age" : "25"
}
-----------------------------------------------------
-----------------------------------------------------
Deleting Document
$ curl -X DELETE http://127.0.0.1:5984/contacts/johndoe?rev=1-
3fcc78daac7a90803f0a5e383f4f1e1e
{"ok":true,"id":"johndoe","rev":"2-3a561d56de1ce3305d693bd15630bf96"}



Verification :

If you want to Verify the document, you can verify using GET request.Since you are fetching a deleted document, this will give you an error message as shown below −

$ curl -X GET http://127.0.0.1:5984/contacts/johndoe
{"error":"not_found","reason":"deleted"}



Visit :


Discussion



* You must be logged in to add comment.