How can I delete multiple documents in CouchDB?

Mike Baranczak picture Mike Baranczak · May 1, 2012 · Viewed 16.6k times · Source

I want to delete all documents where foo equals x. Seems like a pretty basic operation, but I just can't figure it out.

I know how to delete an individual document, but that's not good enough - I may have to delete a few thousand at a time.

How do I bulk delete documents in CouchDB?

Answer

lukecampbell picture lukecampbell · May 1, 2012

I don't know if it's the right way but make a view that exposes the foo field, query the view for the doc._ids of all your documents that you want to delete, and make a bulk update against all your documents. So two (ideally) calls to couch.

http://comments.gmane.org/gmane.comp.db.couchdb.user/11222

Has a similar way to go about it.

Do a bulk update on all the documents you want to delete and update doc._deleted=true following the example in Bulk deletion of documents