CouchDB Delete Document
CouchDB Delete Document using Fauxton
Open the Fauxton url:http://127.0.0.1:5984/_utils/
First select the database which contains all your documents. Here is all three documents in database “employees”:
Select the specific document which you want to delete and click on the delete icon encircled in red.
You will see a pop-up message that “Are you sure you want to delete this doc?” Click ok.
Now the selected document is deleted. You can see here only two documents.
CouchDB Delete Document Using cURL utility
CouchDB facilitates you to delete a document by sending an HTTP request to the server using DELETE method through cURL utility.
Syntax:
Note: -X is used to specify a custom request method of HTTP which is used while communicating with the HTTP server. To delete a dcoment, we have to pass the recent revision id through the url with /database_name/database_id/. “?” is used to mention attributes of any data structure.
Example:
We have a document in our database named “my_database” with id 001. To delete this document first get the rev id of the document by using the following command:
Here rev id is “2-5fef7ea4661b53c017e167809e4f2beb”.
Now use the following command to delete the document having the id “001”.
The response of CouchDB for this command contains 3 fields:
- “ok”: It specifies that the operation is successful.
- “id”: It stores the id of the document.
- “rev”: This indicates the revision id. Every time you revise (update,modify or delete) a document a _rev value will be generated by CouchDB. If you want to update or delete a document, CouchDB expects you to include the _rev field of the revision you want to change. When CouchDB accepts the change, it will generate a new revision number.
Verification
You can verify that your document is deleted by using the following command:
Here, you can’t see the document because it is deleted.