0

So I've been on this for the past 2 days now and I just can't wrap my head around it: I've created a database on mongodb aswell as a Web Api using the Asp.Net visual studio template. The Api works fast locally and gives me the correct responses, but when deployed to azure I always get

System.TimeoutException: A timeout occurred after 30000ms selecting a server using CompositeServerSelector

I've made a pastebin which shows the whole error

So far I've tried:

return "Test string"

which works but as soon as I try to bring mongo into this it times out. Even if I'm just trying to name the database.

return _mongoclient.GetDatabase("MyDatabase").ToString()
Ayes
  • 15
  • 5

1 Answers1

-1

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")

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.

As you can see in this answer https://stackoverflow.com/a/43484598/19493343

  • I'm not connecting to Mongo lab. Just a normal cluster database. – Ayes Nov 24 '22 at 23:57
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – SoySolisCarlos Nov 27 '22 at 10:02