I have created a Cosmos DB database in Azure and using Mongo API. I have created the client and configured like this-
_mongoDbConnectionString = configuration["MongoDBConnectionString"];
_databaseName = configuration["MongoDBName"];
_client = new MongoClient(_mongoDbConnectionString);
_database = _client.GetDatabase(_databaseName);
_collectionName = configuration["MongoDBCollectionName"];
Then trying to write data-
_database.GetCollection<dynamic>(_collectionName).InsertOne(data);
It fails with error-
A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/botframeworkcosmos.documents.azure.com:10255" }", EndPoint: "Unspecified/botframeworkcosmos.documents.azure.com:10255", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: 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
I tried this solution- A timeout occured after 30000ms selecting a server using CompositeServerSelector but it did not work.
I also tried setting the SSL policies like this to configure the client-
_mongoDbConnectionString = configuration["MongoDBConnectionString"];
_databaseName = configuration["MongoDBName"];
MongoClientSettings settings = MongoClientSettings.FromUrl(
new MongoUrl(_mongoDbConnectionString)
);
settings.SslSettings =
new SslSettings() { EnabledSslProtocols = SslProtocols.Tls12 };
_client = new MongoClient(settings);
_database = _client.GetDatabase(_databaseName);
_collectionName = configuration["MongoDBCollectionName"];
I still get the same error. What is weird is, the same code, it was all working yesterday.
Update I deleted the database and created a new one. Still same problem.
Any idea what could be the issue?