Skip to content

Commit 99342a7

Browse files
committed
Fix getDefaultDatabaseName to handle +srv URLs.
Fixes #1977, fixes #1861
1 parent 1574aff commit 99342a7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Jenssegers/Mongodb/Connection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function getDatabaseName()
128128
protected function getDefaultDatabaseName($dsn, $config)
129129
{
130130
if (empty($config['database'])) {
131-
if (preg_match('/^mongodb:\\/\\/.+\\/([^?&]+)/s', $dsn, $matches)) {
131+
if (preg_match('/^mongodb(?:[+]srv)?:\\/\\/.+\\/([^?&]+)/s', $dsn, $matches)) {
132132
$config['database'] = $matches[1];
133133
} else {
134134
throw new InvalidArgumentException("Database is not properly configured.");

0 commit comments

Comments
 (0)