c# - 先前使用“Cluster.ConnectAsync”指定时如何获取存储桶
问题描述
我使用以下代码在 DI 中启动了集群:
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);
});
由于我在初始化过程中指定了存储桶名称,我以后如何在不提供存储桶名称的情况下访问它?
我不能使用 Cluster.BucketAsync() 之类的东西,因为它在这里需要存储桶名称(当我之前指定了所需的存储桶名称时,必须再次指定名称有什么意义?)。
我试过了,Cluster.Buckets.GetAllBucketsAsync()
但我得到了ArgumentNullException
;使用Cluster.Buckets.GetAllBucketsAsync(new GetAllBucketsOptions())
或Cluster.Buckets.GetAllBucketsAsync(GetAllBucketsOptions.Default)
不工作(同样的错误)。
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)
环境:
- .NET 核心 5
- CouchbaseNetClient 3.1.3
- Couchbase 服务器社区-6.6.0
- 在 Docker 上运行
注意:这是来自 Couchbase 论坛的交叉帖子:https ://forums.couchbase.com/t/how-to-get-the-bucket-when-previously-specified-with-cluster-connectasync/29877
解决方案
事实证明,这是一个已知的错误GetAllBucketsAsync()
。
- 在 Couchbase 的论坛上调用 GetAllBucketsAsync() 时出现 System.ArgumentNullException
- [NCBC-2551] GetAllBucketsAsync 总是在 Couchbase 问题跟踪上抛出 ArgumentNullException(验证)
推荐阅读
- swift - 如何制作一个采用 Binding 并将其传递给视图中的另一个 Binding 的视图 - SwiftUI
- java - 部署有效,JPA 有效,JawsDB 有效,但它们不能一起工作
- inno-setup - 为什么在 Inno Setup 中会多次调用 ShouldShipPage 函数
- reactjs - 切换时如何隐藏/显示图像?
- python - pyright:在具有最小值/最大值的同质列表中使用 TypeVar
- r - 然后在函数中用作 df 的反应性 CSV 选择
- java - 无法跨越和左对齐 GridBagLayout 中的文本字段
- perl - perl 指针数组引用的取消引用
- java - 为什么正则表达式提取在scala中返回错误的值
- android - 在项目或库中找不到清单中引用的类 androidx.core.content.FileProvider