From 6aa4531934004d0de31bf030492fefaca86df603 Mon Sep 17 00:00:00 2001 From: Yury Fedorov Date: Mon, 4 Oct 2021 15:42:50 +0300 Subject: [PATCH] Attempt using selected DB as authSource For BC, this attempt is only made when both connection attempts failed using regular options. An extra attempt shouldn't be made if authSource is explicit. --- adminer/drivers/mongo.inc.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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) {