Reputation: 1290
I am trying to flush all the data in a bucket using the .NET client. This is the code I am using:
_instance = new CouchbaseClient();
_instance.FlushAll();
However, the following exception message is thrown "To flush a Couchbase bucket, use the Couchbase.Management API."
I also have the "Flush" enabled setting turned on.
Upvotes: 3
Views: 1875
Reputation: 11
You can use this code:
var bucket = cluster.OpenBucket("MyBucket");
var manager = bucket.CreateManager("Administrator", "password");
manager.Flush();
Upvotes: 1
Reputation: 291
The below code works successfully in my quick test on a bucket with no load. It uses the cluster manager to perform the flush and not the client. Please test further. The doc reference is http://docs.couchbase.com/couchbase-sdk-net-1.3/#cluster-management-with-the-net-client-library.
var config = (CouchbaseClientSection)ConfigurationManager.GetSection("couchbase");
var cluster = new CouchbaseCluster(config);
cluster.FlushBucket("MyBucket");
I ran into a couple of things that I'll share to avoid the same pains for you. First, System.Configuration must be referenced to use ConfigurationManager. Just putting the using statement in my code did not suffice. I had to add it manually as described in System.Configuration.ConfigurationManager not available?.
Second, use of cluster manager requires the credentials. Thus I had to put those into the app.config file. Example below.
<couchbase>
<servers bucket="MyBucket" bucketPassword="password" username="Administrator" password="password">
<add uri="http://localhost:8091/pools"/>
</servers>
</couchbase>
Upvotes: 5
Reputation: 4865
The error looks to be telling you to use the REST API on port 8091. http://docs.couchbase.com/couchbase-manual-2.5/cb-rest-api/
Though I have to say, if this is a Couchbase bucket, you're probably better off deleting the bucket and recreating it. Doing what you are talking about costs a lot of overhead, but just dropping the bucket should be simple and should be much quicker. You would also use the Admin REST API on port 8091 to do this. Test out each and see if the deleting is better than flushing or vice versa.
Upvotes: 2