How to flush Couchbase bucket from Java code?

前提是你 提交于 2021-01-27 04:51:43

问题


I need to clear a Couchbase bucket each time before unit test runs. I use the Java SDK > 2.0 version. 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 new version.

Is there some way to clear data from bucket? I could delete by fetching all keys of documents and then delete them all, but I want to use more pretty way.


回答1:


Actually in the 2.x SDK you can get a BucketManager out of a Bucket instance, which will allow you to call flush() as wonderfully as before ;)




回答2:


Mind that it might be risky to flush and use N1QL queries afterwards in Community v4.0. My integration tests were failing because some documents didn't get indexed after a few dozens of runs (even after 30 minutes). It's safer to just delete documents.




回答3:


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




回答4:


In the Couchbase Java 2.x SDK API Reference look at BucketFlusher.



来源:https://stackoverflow.com/questions/32287600/how-to-flush-couchbase-bucket-from-java-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!