How to delete all documents in a database?


Is there a simple way to delete all documents in a database, but still preserve the database (not use database.delete() ) besides iterating over all query results and delete one document at a time?


There is a flush() available at the BucketManager and through the web UI. Note that it’s disabled by default (you can enable it in the UI) and it proceeds asynchronously. If you want to use it from unit tests, since the cluster does not currently provide a way to check for completion, you will want to sleep for a period of time.


Ups - sorry I didn’t spec the context. It’s more how I can programmatically do it in CBL2 for Android :slight_smile:

This is where I’m stuck - don’t know how to get a “document” from a Result:

Query query =;
ResultSet rs = query.execute();
for (Result result: rs) {

But also I’m think it should be possible to clear all documents in a DB faster than iterating? But if not, what should “???” look like above?


Best to post to the mobile -> Couchbase Lite category on the forum then!