I am making an app, where i want to use mongodb. I have never used mongo before, so i watched a tutorial on youtube. I registered on mongodb and got the connection string from there using their free plan. This is the code I'm using:
string connectionString = "CONNECTIONSTRING";
string dbn = "DBNAME";
string cn = "COLLECTIONNAME";
var client = new MongoClient(connectionString);
var db = client.GetDatabase(dbn);
var collection = db.GetCollection<FilmModel>(cn);
var results = await collection.FindAsync(_ => true);
foreach (var result in results.ToList())
{
Console.WriteLine($"{result.Id}: {result.Cim}");
}
For the first time, it worked, and I didn't modified anything and restarted the app and nothing happens, for 30s. then, it throws this error:
System.TimeoutException: 'A timeout occurred after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 }, OperationsCountServerSelector }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [], DnsMonitorException : "DnsClient.DnsResponseParseException: Response parser error, 244 bytes available, tried to read 1 bytes at index 244.
But the thing is, somethimes it works, sometimes it doesn't. And I don't modify anything. What am I doing wrong?