using System; using System.Diagnostics; using System.IO; using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; using MongoDB.Bson; using MongoDB.Driver; namespace ConsoleApplication { public static class Server17022 { private static readonly X509Certificate Cert = new X509Certificate2(@"C:\dev\mongodb-client.pfx", "pass"); private static readonly SslSettings SslSettings = new SslSettings { CheckCertificateRevocation = false, ClientCertificates = new[] { Cert }, ServerCertificateValidationCallback = (a, b, c, d) => true }; private static readonly MongoClientSettings ClientSettings = new MongoClientSettings { Server = new MongoServerAddress($ServerAddress$, 37017), SslSettings = SslSettings, UseSsl = true }; private static readonly MongoClient Client = new MongoClient(ClientSettings); private static readonly MongoServer Server = Client.GetServer(); public static void Test() { Parallel.For(0, 1000, i => { PrintDbNames(i); Console.WriteLine("Done " + i); Thread.Sleep(500); }); Console.Write("Done"); Console.WriteLine("Connection Count: {0}", Server.Settings); Console.ReadLine(); } public static void PrintDbNames(int thread) { try { var dbs = Server.GetDatabaseNames(); Debug.WriteLine(dbs.ToJson()); } catch (IOException ioex) { Console.WriteLine(ioex.Message); } } } }