Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Comment on lines +203 to +204
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (preg_match('/^mongodb(:|\+srv:)\\/\\/.+\\/([^?&]+)/s', $this->dsn, $matches)) {
$this->_defaultDatabaseName = $matches[2];
if (preg_match('/^mongodb(?:\+srv)?:\\/\\/.+\\/([^?&]+)/s', $this->dsn, $matches)) {
$this->_defaultDatabaseName = $matches[1];

} else {
throw new InvalidConfigException("Unable to determine default database name from dsn.");
}
Expand Down