Skip to content

Commit

Permalink
Attempt using selected DB as authSource
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
orlangure committed Oct 4, 2021
1 parent dcc754c commit 6aa4531
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions adminer/drivers/mongo.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit 6aa4531

Please sign in to comment.