Join 1M+ other developers and:
- Get help and share knowledge in Q&A
- Subscribe to topics of interest
- Get courses & tools that help you grow as a developer or small business owner
PHP connection to MongoDB cluster
Hello, I’ve difficulties with connection to MongoDB cluster on DigitalOcean by PHP. As we know, we have to use SSL, but I don’t know how. My code is as follows:
<?php require_once __DIR__ . "/vendor/autoload.php"; $db = new MongoDB\Client('mongodb://[myapp].mongo.ondigitalocean.com', array( 'username' => 'doadmin', 'password' => '[password]', 'db' => '[database]', 'authSource' => 'admin', 'replicaSet' => '[replica]', 'tls' => 'true', 'tlsCAFile' => '/usr/share/ca-certificates/app/ca-certificate.pem' )); $db = $conn->[database]; $collection = $db->[collection]; ?>
I am getting an error: ‘Uncaught MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers found’.
Do you know how to connect properly in this case? Thank you 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.×