diff --git a/adminer/drivers/mongo.inc.php b/adminer/drivers/mongo.inc.php index 0067bb3a5..9b5c71494 100644 --- a/adminer/drivers/mongo.inc.php +++ b/adminer/drivers/mongo.inc.php @@ -643,6 +643,11 @@ function connect() { if (($auth_source = getenv("MONGO_AUTH_SOURCE"))) { $options["authSource"] = $auth_source; } + + return connect_with_retries($connection, $server, $options); + } + + function connect_with_retries($connection, $server, $options) { try { $connection->_link = $connection->connect("mongodb+srv://$server", $options); return $connection; @@ -651,10 +656,14 @@ function connect() { $connection->_link = $connection->connect("mongodb://$server", $options); return $connection; } catch (Exception $ex) { - return $ex->getMessage(); + if ($options["authSource"] == "") { + $options["authSource"] = $options["db"]; + return connect_with_retries($connection, $server, $options); + } else { + return $ex->getMessage(); + } } } - return $connection; } function alter_indexes($table, $alter) {