Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A timeout occured after 30000ms selecting a server using CompositeServerSelector

I try to deploy my Mongo database in Mongolabs, everything works fine, and I create a new database. Please see my connectionstring.

    public DbHelper()     {          MongoClientSettings settings = new MongoClientSettings()         {             Credentials = new MongoCredential[] { MongoCredential.CreateCredential("dbname", "username", "password") },             Server = new MongoServerAddress("ds011111.mongolab.com", 11111),             //ConnectTimeout = new TimeSpan(30000)         };          Server = new MongoClient(settings).GetServer();          DataBase = Server.GetDatabase(DatabaseName);      } 

but when I try to connect the database it's shows error like:

enter image description here

like image 895
Ragesh S Avatar asked Jul 09 '15 10:07

Ragesh S


1 Answers

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.

like image 72
Paul Lemke Avatar answered Sep 18 '22 19:09

Paul Lemke