Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delete multiple documents in CouchDB?

Tags:

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?

like image 629
Mike Baranczak Avatar asked May 01 '12 20:05

Mike Baranczak


People also ask

How to delete documents CouchDB?

You can delete a document in CouchDB by sending an HTTP request to the server using DELETE method through cURL utility. Following is the syntax to delete a document. Using −X, we can specify a custom request method of HTTP we are using, while communicating with the HTTP server. In this case, we are using Delete method.

What are documents CouchDB?

Advertisements. Documents are CouchDB's central data structure. Contents of the database will be stored in the form of Documents instead of tables. You can create these documents using cURL utility provided by CouchDB, as well as Futon. This chapter covers the ways to create a document in a database.


2 Answers

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

like image 172
lukecampbell Avatar answered Sep 19 '22 17:09

lukecampbell


It's quite easy with bulk delete: https://wiki.apache.org/couchdb/HTTP_Bulk_Document_API Just POST to _all_docs a list of JSONs that look like:

{"_id": "0", "_rev": "1-62657917", "_deleted": true} 
like image 23
zlr Avatar answered Sep 21 '22 17:09

zlr