A timeout occured after 30000ms selecting a server using CompositeServerSelector

亡梦爱人 提交于 2019-11-27 09:14:59
Ragesh S

I am replacing the connection string method in like below.

new MongoClient("mongodb://username:password@ds011111.mongolab.com:11111/db-name")

Now it's solved.

Please see the answer from Paul Lemke.

Paul Lemke

Add "?connect=replicaSet" to the end of your connection string if connecting to MongoLab.

new MongoClient("mongodb://username:password@ds011111.mongolab.com: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.

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:password@ds011111.mongolab.com:11111/db-name?connect=replicaSet")

Then you can change the selected DB Later

mDb = mClient.GetDatabase(mongoDBName);
Ramakrishna

Make sure the database username is also case sensitive. I ran into this issue because of case sensitivity of the username.

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.

Same Error Message but not encountered with a MongoLabs deployment.

I just encountered the same error listed in the title with an Asp.Net Core App. My issue was due to an IOC configuration issue.

In my IOC container, my wrapped MongoClient instance was configured with a dependency transient lifestyle.

Per The MongoDb C# Driver:

It is recommended to store a MongoClient instance in a global place, either as a static variable or in an IoC container with a singleton lifetime.

I promoted the lifestyle of my object to a singleton and it resolved the issue.

I am using:

  • .Net Core 2.0
  • Mongo C# Driver version 2.5
  • Castle Windsor for my IOC version 3.3.0

Please reference the C# Driver Client section: http://mongodb.github.io/mongo-csharp-driver/2.5/reference/driver/connecting/#re-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!