How to get connection status in the C# MongoDB driver v2.0? How to get connection status in the C# MongoDB driver v2.0? mongodb mongodb

How to get connection status in the C# MongoDB driver v2.0?


There is next workaround for this issue:

var client = new MongoClient(new MongoClientSettings{       Server = new MongoServerAddress("xxxx"),       ClusterConfigurator = builder =>       {             builder.ConfigureCluster(settings => settings.With(serverSelectionTimeout: TimeSpan.FromSeconds(10)));       }});


With the new API :

         try            {                MongoClient client = new MongoClient("xxx");                 // if you're running localhost let the parameter empty                var db = client.GetDatabase("dbName");                var collection = db.GetCollection<BsonDocument>("collectionName");                var filter1 = Builders<BsonDocument>.Filter.Empty;                var filter = new BsonDocument();                var count = 0;                   using (var cursor = await collection.FindAsync(filter))                    {                      while (await cursor.MoveNextAsync())                       {                        var batch = cursor.Current;                        foreach (var document in batch)                        {                          count++;                        }                       }                    }               MessageBox.Show(count.ToString());            }            catch(Exception ex)            {                MessageBox.Show(ex.Message);            }