I am completely at a dead end. I use the latest C # drivers (2.3.0.157) and the latest MongoDB (3.2). The database works as a standalone configuration without replication or shards. I tried to work locally on Windows, and also remotely on Amazon LINUX.
I keep getting a timeout error, but mysteriously sometimes it just works (maybe once every 20-30 attempts).
I create a connection as such:
private static readonly string ConnectionString = ConfigurationManager.ConnectionStrings["MongoDB"].ToString(); private static readonly string DataBase = ConfigurationManager.ConnectionStrings["MongoDBDatabase"].ToString(); private static IMongoDatabase _database; public static IMongoDatabase GetDatabase(string database) { if (_database == null) { var client = new MongoClient(ConnectionString); _database = client.GetDatabase(database); } return _database; }
And calling it like this:
public static List<Earnings> GetEarnings() { var db = GetDatabase(DataBase); if (db == null) return new List<Earnings>(); var logs = db.GetCollection<Earnings>("EarningsData"); var all = logs.Find(new BsonDocument()).ToEnumerable().OrderBy(x => x.Symbol).ToList(); return all; }
And it will be time on the logs.Find part of the method. Here's the full message:
Additional Information:
After 30000 ms after selecting a server using CompositeServerSelector {Selectors = ReadPreferenceServerSelector {ReadPreference = {Mode = Primary, TagSets = []}}, LatencyLimitingServerSelector {AllowedLatencyRange = 00: 00: 00.0150000}, a timeout is issued. The client view of the cluster state is {ClusterId: "1", ConnectionMode: "Direct", Type: "Unknown", Status: "Disabled", Servers: [{ServerId: "{ClusterId: 1, EndPoint:" XX.XX. XX.XX: 27017 "}", EndPoint: "XX.XX.XX.XX: 27017", Status: "Disabled", Type: "Unknown"}]}.
I tried to use the fully qualified host name by adding connect = direct and connect = replicaSet to the connection string using MongoClientSettings instead of the connection string and everything else that I could find on forums and StackOverflow. I am at a loss and do not even know where to look further. Any tips?
I also have to add, I can connect perfectly from the command line and RoboMongo ...
mongodb mongodb-.net-driver
user1464246
source share