What is the expected behavior of the below code?
using System;
using System.Collections.Generic;
using Couchbase;
using Couchbase.Configuration.Client;
namespace CouchbaseBucketName
{
internal class Program
{
private static void Main(string[] args)
{
var config = new ClientConfiguration
{
Servers = new List<Uri>
{
new Uri("http://localhost:8091/pools"),
},
BucketConfigs = new Dictionary<string, BucketConfiguration>
{
{ "store", new BucketConfiguration { BucketName = "test_store", Password = "password" } }
}
};
using (var cluster = new Cluster(config))
{
var bucket = cluster.OpenBucket("store");
bucket.Upsert("1", new { Value = 2 });
}
}
}
}
I was expecting ‘store’ to act as an alias for the actual bucket configuration I wanted to use, i.e. open the bucket defined in config.BucketConfigs["store"]
which is the ‘test_store’ bucket. This is almost how it behaves - it uses the bucket configuration config.BucketConfigs["store"]
; however, it ignores the BucketName
property and still writes to bucket ‘store’.
Am I just misinterpreting things, or is this a bug? Below is the code snippet from the [.net client]((https://github.com/couchbase/couchbase-net-client/blob/master/Src/Couchbase/Core/ClusterController.cs#L116) with the unexpected behavior for this particular code path.
public IBucket CreateBucket(string bucketName)
{
//try to find a password in configuration
BucketConfiguration bucketConfig;
if (_clientConfig.BucketConfigs.TryGetValue(bucketName, out bucketConfig)
&& bucketConfig.Password != null)
{
// return CreateBucket(bucketName, bucketConfig.Password); <- Existing implementation
return CreateBucket(bucketConfig.BucketName, bucketConfig.Password); // Expected implementation
}
return CreateBucket(bucketName, string.Empty);
}
Thanks