我有一个API方法,当命中时,查询MongoDb集合中与给定id相关的所有条目(通常是2或3个结果。)同样的查询在我的项目的其他地方进行,没有错误,但是当它被创建时通过这个API方法,我得到频繁的Socket Exceptions如下:
[IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.]
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size):241
MongoDB.Bson.IO.ByteBufferFactory.LoadFrom(Stream stream):37
MongoDB.Driver.Internal.MongoConnection.ReceiveMessage[TDocument](BsonBinaryReaderSettings readerSettings, IBsonSerializer serializer, IBsonSerializationOptions serializationOptions):174
MongoDB.Driver.Operations.QueryOperation`1.GetFirstBatch(IConnectionProvider connectionProvider):204
MongoDB.Driver.Operations.QueryOperation`1.Execute(IConnectionProvider connectionProvider):0
HireSpaceVenue.Data.BookingsData.GetBookingLines(IMongoQuery query) in c:\a\src\HireSpaceVenue.Data\BookingsData.cs:474
HireSpaceVenue.Data.BookingsData.HireSpaceVenue.Data.Interfaces.IBookingsData.GetBookingLinesByBookingId(String bookingId) in c:\a\src\HireSpaceVenue.Data\BookingsData.cs:147
HireSpaceVenueWeb.Controllers.EnquiriesController.GetUpdate(String bookingId) in c:\a\src\HireSpaceVenueWeb\Controllers\EnquiriesController.cs:130
[SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond]
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size):172
//build query
...
// initialise the connection
MongoClient client = new MongoClient(_mongoConnectionString);
MongoServer server = client.GetServer();
MongoDatabase database = server.GetDatabase(_databaseName);
// get the collection
MongoCollection<LazyBsonDocument> bookinglines =
database.GetCollection<LazyBsonDocument>("bookinglines");
// query the collection
MongoCursor<LazyBsonDocument> mongoCursor = bookinglines.Find(query);
// do something with the retrieved data
...
这段代码包含在一个从多个地方调用的方法中,但是当我从API方法调用它时,我似乎只能得到超时问题。
任何解释/可能的原因?