From 925afd33fd8327f85a2d37ab127eb6bb4fb83d57 Mon Sep 17 00:00:00 2001 From: kublermdk Date: Mon, 28 Oct 2019 18:25:35 +0800 Subject: [PATCH] Updated the getDefaultDatabaseName to include SRV support as per https://github.com/yiisoft/yii2-mongodb/issues/283 and tested with https://gist.github.com/kublermdk/3b073b82441ff8fdd7fb5044ad5e32ef --- src/Connection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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."); }