I am using c# .net core to connect to mongo db.The mongo db uses ssl and has a certificate. The certificate is placed in the current directory. The driver version is 2.10.4
string filePath = Directory.GetCurrentDirectory() + "\\somename.pfx";
// var cert = new X509Certificate2(filePath);
var cert = new X509Certificate2(filePath, "password");
var settings = new MongoClientSettings
{
SslSettings = new SslSettings
{
ClientCertificates = new[] { cert },
},
UseSsl = true
};
settings = MongoClientSettings.FromConnectionString(ApplicationConstants.MongoDBConnectionStr);
var client = new MongoClient(settings);
var db = client.GetDatabase(databaseName);
var collection = db.GetCollection<BsonDocument>(collectionName);
var log = db.GetCollection<BsonDocument>("name");
var dataList = collection.Find(Builders<BsonDocument>.Filter.Empty).ToList();
however it throws an exception at the line above
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", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server. ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.