Connecting DigitalOcean Managed MongoDB to Laravel (connection error calling ismaster)

I’m attempting to set up Laravel with the Managed MongoDB provided by DigitalOcean, though for some reason the database is not connecting.

I’ve hit a wall and I think it’s something to do with authSource, but can’t replicate it via cli otherwise…

.env file



'connectionmethod' => [
    'driver' => 'mongodb',
    'dsn' => env('MONGO_DSN'),
    'database' => env('MONGO_DATABASE', ''),
    'username' => env('MONGO_USER', ''),
    'password' => env('MONGO_PASSWORD', ''),
    'options'  => [
        'tls' => (bool) env('MONGO_TLS', false),
        'tlsCAFile' => env('MONGO_TLS_CERT', null),
        'authSource' => 'admin',
        'db' => 'admin',
        'database' => 'admin',

The above causes the following error:

ERROR: No suitable servers found (`serverSelectionTryOnce` set): [connection error calling ismaster on 'digitaloceanhostname'
(MongoDB\\Driver\\Exception\\ConnectionTimeoutException(code: 13053): No suitable servers found (`serverSelectionTryOnce` set): [connection error calling ismaster on 'digitaloceanhostname:27017']

However, when using the CLI to call ismaster, it works:

# mongo "mongodb+srv://MONGO_USER:MONGO_PASSWORD@digitaloceanhostname/MONGO_DATABASE?authSource=admin" --eval 'printjson(db.runCommand({"isMaster": 1}))' --ssl --sslCAFile ./mongo-db-cert.crt

Running it without the ?authSource=admin causes an authentication error, which is making me think the connection error from laravel is the same thing.


# mongo --version
MongoDB shell version v3.6.8

# apt list --installed | grep php | grep mongo
php7.4-mongodb/focal,now amd64 [installed]

# php artisan --version
Laravel Framework 5.8.38

I’m probably missing something obvious, but after looking at this all day any input is appreciated!

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
July 28, 2021
Accepted Answer

Hi there,

I’ve just tested this and I was able to get it working by removing the ?authSource=admin from the database URL in the .env file.

Hope that this helps.

Regards, Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up