Couchbase multiple buckets in .NET app.config

The Couchbase.Net manual says that I can configure my client this way:

<couchbase><servers bucket="default" bucketPassword="">
  <add uri="http://192.168.0.2:8091/pools/default"/>
  <add uri="http://192.168.0.3:8091/pools/default"/>
</servers></couchbase>

Is there a way to define sevral buckets in app.config and then switch between them in my application?

+3
source share
2 answers

As suggested by John, I used this configuration:

<configuration>
  <configSections>
    <sectionGroup name="couchbase">
      <section name="bucket-1" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
      ...
      <section name="bucket-N" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
    </sectionGroup>
  </configSections>
  ...
  <couchbase>
    <bucket-1>
      <servers bucket="bucket-1" bucketPassword="pass">
        <add uri="http://10.0.0.1:8091/pools/default"/>
        <add uri="http://10.0.0.2:8091/pools/default"/>
      </servers>
    </bucket-1>
  </couchbase>
  ...
</configuration>

Then in the application code you can get the bucket client:

var client = new CouchbaseClient((CouchbaseClientSection)ConfigurationManager.GetSection("couchbase/bucket-1"));

It would be nice if the developers of the .Net couchbase library implement such a configuration.

+4
source

I found a way for the above problem.

We can use the CouchbaseClient constructor overload and pass in the bucketname and password. Example: var client = new CouchbaseClient ("default", "");

bucket web.cong.

0

All Articles