How to clear a Couchbase bucket from Java code?

I need to empty the Couchbase bucket every time before running the unit test. I am using Java SDK version> 2.0. In previous versions, I found this wonderful method http://www.couchbase.com/autodocs/couchbase-java-client-1.1.1/com/couchbase/client/ClusterManager.html#flushBucket(java.lang.String) , but it does not exist in the new version.

Is there a way to clear data from a bucket? I could delete by extracting all the keys of the documents and then delete them all, but I want to use it more beautifully.

+5
source share
4 answers

Actually in the SDK 2.x, you can get the BucketManager from the Bucket instance, which allows you to call flush() as wonderful as before;)

+5
source

Keep in mind that it can be risky to clean up and use N1QL queries afterwards in Community v4.0. My integration tests failed because some documents were not indexed after dozens of runs (even after 30 minutes). It’s safer to just delete documents.

+1
source

You can use the REST API to remove the bucket: http://docs.couchbase.com/admin/admin/REST/rest-bucket-intro.html

0
source

All Articles