首页 > 解决方案 > .Net 5 在 Ubuntu 中无法连接 mongodb

问题描述

我已经测试了 Windows 和 Mac 以连接到远程数据库。只有 Docker 中部署的 Ubuntu 无法连接我对网络层一无所知。帮助

这是地址 mongodb+srv://xxxx:xxxx@cluster0.xxxxx.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"

这是日志

System.TimeoutException: A timeout occurred after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/cluster0-shard-00-00.koby6.mongodb.net:27017" }", EndPoint: "Unspecified/cluster0-shard-00-00.koby6.mongodb.net:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server.

---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: PartialChain

at System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken message, ExceptionDispatchInfo exception)

at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)

at MongoDB.Driver.Core.Connections.SslStreamFactory.CreateStreamAsync(EndPoint endPoint, CancellationToken cancellationToken)

at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)

标签: c#.netmongodbnetworking

解决方案


最后我通过调用解决了我自己的问题

apt-get install -y wget
apt-get install -y apt-transport-https

错误不再发生


推荐阅读