I have a single primary instance of a MongoDB to connect to. I am using the C# driver (latest revision) to connect and utilise MongoDB.
My client application is multi-threaded whereby processes will run periodically at different intervals to produce reports. When more than one thread is running, and I call various functions on the driver (e.g server.DatabaseExists(...)), I am consistently met with an exception.
"The requested name is valid, but no data of the requested type was found"
at System.Net.Dns.GetAddrInfo(String name)
at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
at MongoDB.Driver.MongoServerAddress.ToIPEndPoint(AddressFamily addressFamily) in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoServerAddress.cs:line 195
at MongoDB.Driver.MongoServerInstance.GetIPEndPoint() in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoServerInstance.cs:line 339
at MongoDB.Driver.Internal.MongoConnection.Open() in C:\work\rstam\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 368
at MongoDB.Driver.Internal.MongoConnection.GetNetworkStream() in C:\work\rstam\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 574
at MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage message, SafeMode safeMode, String databaseName) in C:\work\rstam\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 555
at MongoDB.Driver.MongoCursorEnumerator`1.GetReply(MongoConnection connection, MongoRequestMessage message) in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 295
at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst() in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 253
at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext() in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 141
at MongoDB.Driver.MongoDatabase.GetCollectionNames() in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line 645
at MongoDB.Driver.MongoDatabase.CollectionExists(String collectionName) in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line 297
Running one thread does not cause this issue. I am of the understanding that MongoDB is thread-safe, so I am at loss to understand the cause and the remedy.
The MongoDB server currently uses a thread per connection plus a number of internal threads. You can list all threads (including idle and system) using db. currentOp(true) in the mongo shell. If you have 8 incoming requests, each of those will be handled by a separate connection thread.
Each MongoDB collection can have multiple documents. A document is equilant to row in a table in RDBMS. To create a collection, use the db. createCollection() command.
By default, MongoDB is a strongly consistent system. Once a write completes, any subsequent read will return the most recent value. Cassandra, by default, is an eventually consistent system. Once a write completes, the latest data eventually becomes available provided no subsequent changes are made.
Many to Many relationships are a type of mongodb relationship in which any two entities within a document can have multiple relationships. In this relationship, we can consider a case of Online courses website where there are many courses and also many users.
The only "solution" I've found was to recycle the Application Pool that's hosting my website\service calling the mongo client.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With