A timeout occured after 30000ms selecting a server using CompositeServerSelector
Solution 1:
Add "?connect=replicaSet" to the end of your connection string if connecting to MongoLab.
new MongoClient("mongodb://username:[email protected]:11111/db-name?connect=replicaSet")
This JIRA ticket has some details: https://jira.mongodb.org/browse/CSHARP-1160
Basically the default is to connect to a replica set member. But MongoLab's Single-Node settings are actually a single node replica set and this causes us to not trust it. Appending ?connect=replicaSet to your connection string will force the driver to move into replica set mode and all will work.
Found that info here.
Solution 2:
I am replacing the connection string method in like below.
new MongoClient("mongodb://username:[email protected]:11111/db-name")
Now it's solved.
Please see the answer from Paul Lemke.
Solution 3:
Make sure your current ip address is white-listed in mongo db server. If you change your internet provider new IP needs to be white-listed.
Solution 4:
Make Sure your auth db is set correctly.
I ran into this issue when I mentioned only the DB i wanted to connect to , and my auth db was different (other than admin db ).
The db-name in this line is considered as the auth DB .
new MongoClient("mongodb://username:[email protected]:11111/db-name?connect=replicaSet")
Then you can change the selected DB Later
mDb = mClient.GetDatabase(mongoDBName);