试图通过下面的代码访问最近在AWS中创建的documentdb数据库;
public GetEntities()
{
_client = new MongoClient("mongodb://username:password@mynode.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false");
_database = _client.GetDatabase("testdb");
_collection = _database.GetCollection<UserObject>("testcollection");
}
public bool Handle(GetDocumentsQuery message)
{
try
{
_collection.InsertOne(message);
var asd = _collection.Find(f => f.Name != "asd").ToList();
}
catch (System.Exception ex)
{
}
return true;
}
}
抛出这个异常:
ex {" 30000ms选择服务器后发生超时CompositeServerSelector{选择器=MongoDB.Driver.MongoClient + AreSessionsSupportedServerSelector,LatencyLimitingServerSelector{AllowedLatencyRange = 00:00:00.0150000}、OperationsCountServerSelector}。集群状态的客户端视图为{ClusterId: "1",类型:"未知",状态:"服务器:[{ServerId: "{ClusterId: 1,端点:"不明/mydocdbname.amazonaws.com: 27017"}"端点:"不明/mydocdbname.amazonaws.com: 27017",ReasonChanged:心跳"状态"断开连接"服务器版本:;TopologyVersion:, Type: "Unknown"MongoDB.Driver。发生了一个异常打开到服务器的连接。——比;System.Security.Authentication.AuthenticationException:远程根据验证程序,证书无效。 r nSystem.Net.Security.SslState.InternalEndProcessAuthentication (LazyAsyncResultlazyResult) r nSystem.Net.Security.SslState.EndProcessAuthentication (IAsyncResult结果) r nSystem.Net.Security.SslStream.EndAuthenticateAsClient (IAsyncResultasyncResult) r nSystem.Threading.Tasks.TaskFactory
1.FromAsyncCoreLogic(IAsyncResult iar, Func
2 endFunction, Action1 endAction, Task
1 promise, BooleanrequiresSynchronization)rn——结束之前的堆栈跟踪抛出异常的位置——rn atSystem.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) r nSystem.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) r nMongoDB.Driver.Core.Connections.SslStreamFactory.d__4.MoveNext () r n—从抛出异常的前一个位置开始的堆栈跟踪结束——rn at system . runtime . compilerservices . taskawait . throwfornonsuccess(任务任务) r nSystem.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) r nMongoDB.Driver.Core.Connections.BinaryConnection.d__51.MoveNext () r nrn在MongoDB.Driver.Core.Connections.BinaryConnection.d__51.MoveNext()rn——从抛出异常的前一个位置开始的堆栈跟踪结束——rn at system . runtime . compilerservices . taskawait . throwfornonsuccess(任务任务) r nSystem.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) r nMongoDB.Driver.Core.Servers.ServerMonitor.d__33.MoveNext () r n—从抛出异常的前一个位置开始的堆栈跟踪结束——rn at system . runtime . compilerservices . taskawait . throwfornonsuccess(任务任务) r nSystem.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) r nSystem.Runtime.CompilerServices.TaskAwaiter。ValidateEnd(工作任务) r n在"MongoDB.Driver.Core.Servers.ServerMonitor.d__35.MoveNext (),LastHeartbeatTimestamp:"2022 - 07 - 05 - t18:31:52.4889181z"LastUpdateTimestamp:"2022 - 07 - 05 - t18:31:52.4889181z"}]} !"}系统。异常{系统。TimeoutException}
这里缺少什么?
您的问题的答案是。net驱动程序不支持ssl_ca_certs
连接字符串选项,您应该在操作系统级别配置CA证书