Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delete all records in a database in CouchDB?

Tags:

couchdb

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.

like image 878
Jakub Arnold Avatar asked Mar 12 '12 13:03

Jakub Arnold


2 Answers

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);
  });
});
like image 134
Rez Avatar answered Sep 20 '22 14:09

Rez


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])
like image 25
amagard Avatar answered Sep 20 '22 14:09

amagard