1

I have a database where I need to remove documents with a regular interval. It is going to be in the ballpark of 100k documents per batch.

As of today that is achieved by first doing a request to a view which returns a list of the _id:s and _rev:s of the documents to be removed.

I then do a http DELETE request to hostname/database/_id?=_rev for each of those documents.

To me that seems ridiculously inefficient since I must do a http request for each of those 100k documents.

Is there any more efficient way of deleting large ammounts of documents in couch? I have been looking for a command similar to the POST for creating new documents, where you send the data in the body of the http. Or way of doing this in a mapreduce. But so far no luck.

Einar Sundgren
  • 4,325
  • 9
  • 40
  • 59

1 Answers1

3

You can bundle all of the delete operations into one bulk_docs update.

For 100k documents, you will notice that the operation takes a little time, but it is much faster than individual DELETE updates.

JasonSmith
  • 72,674
  • 22
  • 123
  • 149
  • I'm prepared for the operation to take some time. Still this is far better than what I have. I must have forgotten that you could set the _deleted flag from that update. One question though, will this result in a real delete of the document from the db when compact runs or will it just make it invisible? – Einar Sundgren Oct 29 '13 at 20:02