Is there any way that I can drop all data from a CouchDB database?
What I'm doing currently is dropping and re-creating the whole database
curl -X DELETE http://localhost:5984/foobar
curl -X PUT http://localhost:5984/foobar
but I'm not sure if this is the best way to do this.
The code below deletes all databases (not all records!) using Node.js. You need to install nano and after that execute following code:
var nano = require('nano')('http://localhost:5984');
nano.db.list(function(err, body) {
body.forEach(function(db) {
nano.db.destroy(db);
});
});
Here is a python script to do the job:
import couchdb
couch = couchdb.Server('http://localhost:5984/')
couchdb = 'DATABASE'
db = couch[couchdb]
for id in db:
db.delete(db[id])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With