Mongodb C# 'System.TimeoutException [英] Mongodb C# 'System.TimeoutException
本文介绍了Mongodb C# 'System.TimeoutException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 mongodb 中遇到了奇怪的异常.我在 vs 中编写了一个简单的服务,并且一直运行到昨晚.但是现在当我通过 VS 运行我的服务时,我得到了这个异常:
I got strange exception in mongodb.I wrote a simple service into vs and worked well till last night. but now when I am running my service by VS I get this exception:
An exception of type 'System.TimeoutException' occurred in MongoDB.Driver.Core.dll but was not handled in user code
Additional information: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference = { Mode = Primary, TagSets = [] } }, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "127.0.0.1:27017" }", EndPoint: "127.0.0.1:27017", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:27017
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.Core.Connections.TcpStreamFactory.<ConnectAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.Core.Connections.TcpStreamFactory.<CreateStreamAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__47.MoveNext()
--- End of inner exception stack trace ---
at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__47.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at MongoDB.Driver.Core.Servers.ClusterableServer.<HeartbeatAsync>d__42.MoveNext()" }] }.
为什么会出现此异常,我该如何处理?为什么我的服务以前运行良好?这是我遇到此异常的地方:
why I got this exception and how could I handle it? why my service worked well before? this is where I got this exception:
public static IList<Location> GetFinalLocationsInTopicInLocationTable(string topic)
{
logger.Trace(Constants.LOG_MESSAGE_METHOD_STARTED);
var collection = GetDbMongo().GetCollection<Location>(DB_COLLECTION_LOCATIONS);
var matchFilter = Builders<Location>.Filter.Regex("Topic", topic);
var groupFilter = new BsonDocument { { "_id", "$DeviceId" }, { "max", new BsonDocument("$max", "$CreationDateTime") } };
var location = collection
.Aggregate()
.Match(matchFilter)
.Group(groupFilter)
.ToList(); // -----I got this exception
推荐答案
我解决了这个问题.我的问题是:我的mongodb服务被停止
.我不知道为什么它停止了,但是当我启动它时,问题就消失了.
I resolve that. my problem was:
my mongodb service was stopped
. I do not know why it was stopped but when I start it, the problem gone.
这篇关于Mongodb C# 'System.TimeoutException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文