Skip to content

Commit b07b773

Browse files
committed
Fix authentication issue
1 parent b1ba09e commit b07b773

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

config.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@
2727
* @var string
2828
*/
2929
define('MPG_MONGODB_PORT', '27017');
30+
31+
/**
32+
* MongoDB server database.
33+
*
34+
* @var string
35+
*/
36+
define('MPG_MONGODB_DATABASE', '');

src/Controllers/IndexController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ public function indexAction() : Response {
1212

1313
$databasesNames = [];
1414

15-
foreach ($mongoDBClient->listDatabases() as $databaseInfo) {
16-
$databasesNames[] = $databaseInfo['name'];
15+
if ( !empty(MPG_MONGODB_DATABASE) ) {
16+
$databasesNames[] = MPG_MONGODB_DATABASE;
17+
} else {
18+
foreach ($mongoDBClient->listDatabases() as $databaseInfo) {
19+
$databasesNames[] = $databaseInfo['name'];
20+
}
1721
}
1822

1923
return new Response(200, $this->renderView('index', [

src/Helpers/MongoDBHelper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public static function createClient() : MongoDBClient {
2525
$clientUri .= ':' . MPG_MONGODB_PORT;
2626
}
2727

28+
if ( !empty(MPG_MONGODB_DATABASE) ) {
29+
$clientUri .= '/' . MPG_MONGODB_DATABASE;
30+
}
31+
2832
return new MongoDBClient($clientUri);
2933

3034
}

0 commit comments

Comments
 (0)