MongoDB HeartbeatException:>“MongoDB.Driver.MongoConnectionException

Ane*_*esh 5 .net c# configuration mongodb mongodb-atlas

System.TimeoutException:使用 CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{AllowedLatencyRange = 00:00:00.0150000 } } 选择服务器 30000 毫秒后发生超时。集群状态的客户端视图为 { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/mongodb. net:27017" }",EndPoint:"未指定/mongodb.net:27017",ReasonChanged:"Heartbeat",状态:"已断开连接",ServerVersion:,TopologyVersion:,类型:"未知",HeartbeatException:"MongoDB.Driver。 MongoConnectionException: 打开与服务器的连接时发生异常。 ---> MongoDB.Driver.MongoConnectionException: 从服务器接收消息时发生异常。 ---> System.IO.EndOfStreamException: 尝试读取末尾内容在 MongoDB.Driver.Core.Misc.StreamExtensionMethods.d__4.MoveNext() --- 抛出异常的上一个位置的堆栈跟踪结束 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 处MongoDB.Driver.Core.Connections.BinaryConnection.d__54.MoveNext() 处的 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) --- 内部异常堆栈跟踪结束 --- MongoDB.Driver.Core.Connections 处。 BinaryConnection.d__57.MoveNext() --- 从先前引发异常的位置开始的堆栈跟踪结束 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 处,在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 处在 MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol1.d__16.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MongoDB.Driver.Core.Connections.IsMasterHelper.d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MongoDB.Driver.Core.Connections.ConnectionInitializer.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MongoDB.Driver.Core.Connections.BinaryConnection.d__51.MoveNext() --- End of inner exception stack trace --- at MongoDB.Driver.Core.Connections.BinaryConnection.d__51.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MongoDB.Driver.Core.Servers.ServerMonitor.d__32.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at MongoDB.Driver.Core.Servers.ServerMonitor.d__34.MoveNext()", LastHeartbeatTimestamp: "2021-06-12T09:49:42.7901777Z", LastUpdateTimestamp: "2021-06-12T09:49:42.7901777Z" }, { ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/mongodb.net:27017" }", EndPoint: "Unspecified/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. ---> MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server. ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream. at MongoDB.Driver.Core.Misc.StreamExtensionMethods.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MongoDB.Driver.Core.Connections.BinaryConnection.d__54.MoveNext() --- End of inner exception stack trace --- at MongoDB.Driver.Core.Connections.BinaryConnection.d__57.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol1.d__16.MoveNext() --- 从先前引发异常的位置开始的堆栈跟踪结束 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 处 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)在 MongoDB.Driver.Core.Connections.IsMasterHelper.d__6.MoveNext() --- 从先前引发异常的位置开始的堆栈跟踪结束 --- 在 System.Runtime 的 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 处。 MongoDB.Driver.Core.Connections.ConnectionInitializer.d__4.MoveNext() 处的 CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) --- 抛出异常的上一个位置的堆栈跟踪结束 --- 位于 System.Runtime.ExceptionServices.ExceptionDispatchInfo .Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MongoDB.Driver.Core.Connections.BinaryConnection.d__51.MoveNext() --- 内部异常堆栈跟踪结束 --- at MongoDB.Driver .Core.Connections.BinaryConnection.d__51.MoveNext() --- 从先前引发异常的位置开始的堆栈跟踪结束 --- 在 System.Runtime.CompilerServices.TaskAwaiter 的 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 处。 MongoDB.Driver.Core.Servers.ServerMonitor.d__32.MoveNext() 处的 HandleNonSuccessAndDebuggerNotification(Task task) --- 抛出异常的上一个位置的堆栈跟踪结束 --- System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 处在 MongoDB.Driver.Core.Servers.ServerMonitor.d__34.MoveNext()", LastHeartbeatTimestamp: "2021-06-12T09:49:42.7602069Z", LastUpdateTimestamp: "2021-06-12T09:49:42.7602069Z" }, { ServerId:“{ ClusterId:1,EndPoint:“未指定/mongodb.net:27017”}”,EndPoint:“未指定/mongodb.net:27017”,ReasonChanged:“心跳”,状态:“已断开连接”,ServerVersion:,拓扑版本:,类型:“未知”,HeartbeatException:“MongoDB.Driver.MongoConnectionException:打开与服务器的连接时发生异常。---> MongoDB.Driver.MongoConnectionException: 从服务器接收消息时发生异常。---> System.IO.EndOfStreamException:尝试读取超过流末尾的内容。在 MongoDB.Driver.Core.Misc.StreamExtensionMethods.d__4.MoveNext() --- 从先前引发异常的位置开始的堆栈跟踪结束 --- 在 System.Runtime 的 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 处。 CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)位于 MongoDB.Driver.Core.Connections.BinaryConnection.d__54.MoveNext() --- 内部异常堆栈跟踪结束 --- 位于 MongoDB.Driver.Core.Connections.BinaryConnection.d__57。 MoveNext() --- 从先前抛出异常的位置开始的堆栈跟踪结束 --- 在 System.Runtime.CompilerServices 的 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 处。1.d__16.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MongoDB.Driver.Core.Connections.IsMasterHelper.d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MongoDB.Driver.Core.Connections.ConnectionInitializer.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MongoDB.Driver.Core.Connections.BinaryConnection.d__51.MoveNext() --- End of inner exception stack trace --- at MongoDB.Driver.Core.Connections.BinaryConnection.d__51.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MongoDB.Driver.Core.Servers.ServerMonitor.d__32.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at MongoDB.Driver.Core.Servers.ServerMonitor.d__34.MoveNext()", LastHeartbeatTimestamp: "2021-06-12T09:49:42.7401803Z", LastUpdateTimestamp: "2021-06-12T09:49:42.7401803Z" }] }. at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description) at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedHelper.HandleCompletedTask(Task completedTask) at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChanged(IServerSelector selector, ClusterDescription description, Task descriptionChangedTask, TimeSpan timeout, CancellationToken cancellationToken) at MongoDB.Driver.Core.Clusters.Cluster.SelectServer(IServerSelector selector, CancellationToken cancellationToken) at MongoDB.Driver.MongoClient.AreSessionsSupportedAfterServerSelection(CancellationToken cancellationToken) at MongoDB.Driver.MongoClient.AreSessionsSupported(CancellationToken cancellationToken) at MongoDB.Driver.OperationExecutor.StartImplicitSession(CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl1.在 GetUserDetails() 处使用 MongoDB.Driver.FindFluent 1 源处的UsingImplicitSession[TResult](Func 2 func, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl1.FindSync[TProjection](FilterDefinition 1 filter, FindOptions2 选项, CancellationToken CancellationToken) , CancellationToken CancellationToken);2.ToCursor(CancellationToken cancellationToken) at MongoDB.Driver.IAsyncCursorSourceExtensions.ToList[TDocument](IAsyncCursorSource

  public List<User> GetUserDetails(Guid applicationID, Guid UserID)
        {
            var con = new MongoClient(DBConnection.MongoDBConnectionString);
            var db = "UserDB"
            var collection = db.GetCollection<User>("User");
            var filter = Builders<User>.Filter.Eq("userid", UserID.ToString())
                      & (Builders<User>.Filter.Gt("expiryDate", DateTime.Now.ToUniversalTime()));
            var users= collection.Find(filter).ToList().OrderBy(x => x.userstatus).ThenByDescending(x => x.CreatedDate).ToList();
            return users;
        }
Run Code Online (Sandbox Code Playgroud)

我的连接字符串格式

<add name="MongoDefaultConnection" connectionString="mongodb+srv://appname:corfjg#5r@appname.nbf92.mongodb.net/UserDB?retryWrites=true" />
Run Code Online (Sandbox Code Playgroud)