Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save revington/3032934 to your computer and use it in GitHub Desktop.
Save revington/3032934 to your computer and use it in GitHub Desktop.
Delete all non-design docs in CouchDB (using cradle)
var cradle = require('cradle');
var database = 'app';
cradle.setup({
host: '127.0.0.1',
port: 5984,
auth: { username: "YOUR_USERNAME", password: "YOUR_PASSWORD" }
});
var db = new(cradle.Connection)().database(database);
/* Delete non-design documents in a database. */
db.all(function(err, doc) {
/* Loop through all documents. */
for(var i = 0; i < doc.length; i++) {
/* Don't delete design documents. */
if(doc[i].id.indexOf("_design") == -1) {
db.remove(doc[i].id, doc[i].value.rev, function(err, doc) {
console.log(doc);
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment