"No suitable servers found" connecting to MongoDB using PHP

Posted November 2, 2021 122 views


I’m trying to connect from my PHP application to MongoDB instance located in FRA1, but I get this errorr:
No suitable servers found (serverSelectionTryOnce set): [connection error calling hello on ’[app]’]

I’m using PHP 8 with ext v.1.10, MongoDB Server is the 4.4.
The strange thing I see is that the DNS of my connection string (grab from my DO Panel) is [app] but the one but the error talks about [app]

No problem if I try to connect to my instance using clients like MongoDBCompass or Robot3T.

What does that error means?
Thaks in advance,

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi there,

Could you share your PHP connection string that you are using? Make sure to remove any sensitive information before posting it here.

Also I would recommend trying to add +srv to your connection string as follows:

$db = new MongoDB\Client('mongodb+srv://[myapp]', array(
    'username' => 'doadmin',
    'password' => '[password]',
    'db'       => '[database]',
    'authSource' => 'admin',
    'replicaSet' => '[replica]',
    'tls' => 'true',
    'tlsCAFile' => '/usr/share/ca-certificates/app/ca-certificate.pem'