Last Updated: February 25, 2016
·
1.548K
· zanona

Snippet: Flush CouchDB Database inside Futon

When inside Futon database page (http://127.0.0.1:5984/_utils/database.html?database_name), use the following script to delete (flush) all documents except the _design/*** docs.

This was pretty useful for testing in my case:

var couch = new $.futon.CouchDocumentPage();
couch.db.allDocs({success: function (all) {
    var docs = all
        .rows
        .filter(function(item) { return !item.id.match('_design'); })
        .map(function (item) { return {_id: item.id, _rev: item.value.rev}});

    couch.db.bulkRemove({docs: docs}, {success: function (docs) {
        window.location.reload();
    }});
}});

1 Response
Add your response

It is probably an easy job, to transform this into a bookmarklet or a chrome extension to auto-add this as a button into futon's interface. just so it is not necessary the use of snippet anymore.

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside