Blog

DELETE Documents from CouchDB

July 3, 2009

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:

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:

still indicates that the document we just deleted still exists:

DELETE /documentstore/13ce4780-62c8-4074-9955-8c99966b84bb
?rev=1-2901013762

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

If you and your team want to learn more about how to write maintainable unit tests and get the most out of TDD practices, make sure to have look at our trainings and workshops or check out the books section. Feel free to reach out at infonull@nullprincipal-itnull.be.

Profile picture of Jan Van Ryswyck

Jan Van Ryswyck

Thank you for visiting my blog. I’m a professional software developer since Y2K. A blogger since Y2K+5. Provider of training and coaching in XP practices. Curator of the Awesome Talks list. Past organizer of the European Virtual ALT.NET meetings. Thinking and learning about all kinds of technologies since forever.

Comments

About

Thank you for visiting my website. I’m a professional software developer since Y2K. A blogger since Y2K+5. Author of Writing Maintainable Unit Tests. Provider of training and coaching in XP practices. Curator of the Awesome Talks list. Thinking and learning about all kinds of technologies since forever.

Contact information

(+32) 496 38 00 82

infonull@nullprincipal-itnull.be