views:

181

answers:

2

I want to set up a rake task to fill my CouchDB with fixtures data and have to get rid of the data in the database first. A good example for the whole procedure using MySQL can be found here. This examples contains the following part to delete the data of the model in the MySQL database:

# the list of models (pluralized) you want to import, in order
models = ['Cities','Neighborhoods','Shops','Reviews']

# truncate existing tables
models.reverse.each { |model| ActiveRecord::Base.connection.execute("truncate table #{model.underscore}") }

What would be the equivalent for CouchDB? Do I have to take a complete different approach as this concept that is set up for relational databases cannot be applied to document-orientated databases?

Many thanks in advance!

A: 

I think the easiest way to get rid of all the documents in your database is to just delete the database and then re-create it. Does that solve your problem? You'd probably want to have an off-line copy of the design docs so you can put those back after re-creating.

I'm not aware of any way of bulk deleting documents from a CouchDB database.

Ah -- so you want to delete only the documents belonging to one specific Model? In that case, I think you'll have to iterate over a view (either a specific view that iterates over documents belonging to that model or _all_docs) and delete one document at a time.

djc
Sorry, but I think none of this is really helpful/correct.
konrad
Okay... Did I misunderstand your question? If not, why do you think I'm wrong?
djc
A: 

There is no tables and schema, so nothing to truncate. You should delete documents instead. But it's impossible to do things like "delete from" so you should retrieve documents and then delete them using HTTP Bulk Document API.

I guess you need that for development environment, so there are should not be lots of docs and this solution will be acceptable.

Also you can get first bunch docs, bulk delete and then get another bunch of docs, etc... Repeat for every model. I hope that helps.

Sam