Skip to content

Commit ddcaad7

Browse files
committed
Fix getDefaultDatabaseName to handle +srv URLs.
Fixes mongodb#1977, fixes mongodb#1861
1 parent 98a8ef5 commit ddcaad7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Jenssegers/Mongodb/Connection.php

Lines changed: 1 addition & 1 deletion
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)