3 Jul

DELETE Documents from CouchDB

Category:UncategorizedTag: :

To start off, here are the links to my previous posts about CouchDB:

  1. Relaxing on the Couch(DB)
  2. Installing the Couch(DB)
  3. PUTting the Couch(DB) in Your Living Room
  4. GETting Documents From CouchDB

Today, I want to talk about how to delete a document from CouchDB. In order to do that, we have to use the HTTP DELETE operation (how convenient). Removing a document from CouchDB can be done using the following request:

DELETE /documentstore/13ce4780-62c8-4074-9955-8c99966b84bb

This makes CouchDB return the following response:


This confirms that the document has been removed by CouchDB. But is it really gone? Not exactly. We might be able to retrieve it using its revision number. Sending the following request:

GET /documentstore/13ce4780-62c8-4074-9955-8c99966b84bb

still indicates that the document we just deleted still exists:


Notice that the _deleted attribute indicates that the document has indeed been deleted. It’s even possible to resurrect the document at hand by performing an update, bringing the document back amongst the living documents.

However, I don’t consider that a good idea in all scenarios. In fact, as pointed out by this comment on my previous post, one should not blindly rely on the MVCC tokens for version control of documents, something that I neglected to point out in that post. When CouchDB is configured for compaction or replication with other instances of CouchDB, then this approach is not recommended. In case of compaction , CouchDB will actively purge old versions of documents and deleted documents. In case of replication, a particular node in a clustered environment doesn’t necessarily have the complete version history of a document. Bottom line, use this feature very carefully.

For my next post, I will talk about how to create attachment for a document.

Till next time

4 thoughts on “DELETE Documents from CouchDB

  1. A good friend is like a computer;me’enter’ur life,’save’u in my heart,’format ur problems,’shift’u 2opportunities&never’delete’u from memory

Comments are closed.