diff --git a/src/Connection.php b/src/Connection.php index 590f29d82..e13671afb 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -200,8 +200,8 @@ public function setDefaultDatabaseName($name) public function getDefaultDatabaseName() { if ($this->_defaultDatabaseName === null) { - if (preg_match('/^mongodb:\\/\\/.+\\/([^?&]+)/s', $this->dsn, $matches)) { - $this->_defaultDatabaseName = $matches[1]; + if (preg_match('/^mongodb(:|\+srv:)\\/\\/.+\\/([^?&]+)/s', $this->dsn, $matches)) { + $this->_defaultDatabaseName = $matches[2]; } else { throw new InvalidConfigException("Unable to determine default database name from dsn."); }