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
This is where I’m stuck - don’t know how to get a “document” from a Result:
Query query = QueryBuilder.select(SelectResult.all()).from(DataSource.database(database));
ResultSet rs = query.execute();
for (Result result: rs) {
database.delete(???);
}
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!
Sorry, but it seems to me that’s what I did? I someone moved this for me - in that case thanks!
Both “Mobile” and “Couchbase Lite” is listed at the top of this post on my screen now at least.
Indeed, someone moved it for you @bro2.
What you described is the correct procedure. You should select the IDs, then retrieve the document by ID and delete it during the iteration. There is no faster way to do this, as the normal way would be to delete and recreate the database which you have said you don’t want to do (is there a reason why?)
Ok - thanks @borrrden. Think I got that one now.