Forked from ryankirkman/couchdb_delete_non_design_docs.js
Created
June 1, 2016 22:34
-
-
Save msroot/2418aeae1c8fb384b6e2a02064354bb3 to your computer and use it in GitHub Desktop.
Delete all non-design docs in CouchDB (using cradle)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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