1

I initiated the Cluster in DI with the following code:

serviceCollection.AddSingleton<ICouchbaseRepository>(service =>
{
    var couchbaseOptions = service.GetService<AppSettings>()?.CouchbaseOptions
                            ?? throw new NullReferenceException(nameof(CouchbaseOptions));
    var cluster = Cluster.ConnectAsync(new ClusterOptions
    {
        ConnectionString = couchbaseOptions.ConnectionString,
        Buckets = new List<string> { couchbaseOptions.Bucket }, // See here
        UserName = couchbaseOptions.Username,
        Password = couchbaseOptions.Password
    });
    return new CouchbaseRepository(cluster);
});

As I specified the bucket name in the initialisation process, how can I access it later without providing the bucket name?

I cannot use something like Cluster.BucketAsync() as it requires the bucket name here (what’s the point of having to specify the name again when I have specified the desired bucket name previously?).

I tried with Cluster.Buckets.GetAllBucketsAsync() but I got the ArgumentNullException; using Cluster.Buckets.GetAllBucketsAsync(new GetAllBucketsOptions()) or Cluster.Buckets.GetAllBucketsAsync(GetAllBucketsOptions.Default) don’t work either (same errors).

Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'value')
   at Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull(Object value, String parameterName)

   at Newtonsoft.Json.Linq.Extensions.Value[T,U](IEnumerable`1 value)
   at Newtonsoft.Json.Linq.Extensions.Value[U](IEnumerable`1 value)
   at Couchbase.Management.Buckets.BucketManager.GetBucketSettings(JToken json)
   at Couchbase.Management.Buckets.BucketManager.GetAllBucketsAsync(GetAllBucketsOptions options)

Environment:

  • .NET Core 5
  • CouchbaseNetClient 3.1.3
  • Couchbase Server community-6.6.0
  • Runs on Docker

Note: this is a cross-post from Couchbase's forum: https://forums.couchbase.com/t/how-to-get-the-bucket-when-previously-specified-with-cluster-connectasync/29877

Thammarith
  • 662
  • 5
  • 19
  • Cross posting discussion from the forums: https://forums.couchbase.com/t/how-to-get-the-bucket-when-previously-specified-with-cluster-connectasync/29877/4 – Matthew Groves Mar 22 '21 at 13:20

1 Answers1

0

It turned out that this is a known bug from GetAllBucketsAsync().

Thammarith
  • 662
  • 5
  • 19