Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Connection.php for add +srv (mongodb+srv) #330

Closed
wants to merge 2 commits into from

Conversation

metola
Copy link

@metola metola commented Jan 10, 2021

Fix issue #304
This is need if you create a cloud cluster https://cloud.mongodb.com/ and need conection mongodb+srv

Q A
Is bugfix? yes
New feature? yes
Breaks BC? no
Tests pass? no
Fixed issues #304

@metola metola changed the title Update Connection.php for add +srv Update Connection.php for add +srv (mongodb+srv) Jan 11, 2021
Comment on lines +203 to +204
if (preg_match('/^mongodb(:|\+srv:)\\/\\/.+\\/([^?&]+)/s', $this->dsn, $matches)) {
$this->_defaultDatabaseName = $matches[2];
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];

@samdark samdark added this to the 2.1.12 milestone Jan 11, 2021
@samdark
Copy link
Member

samdark commented Jan 11, 2021

Also need a line for CHANGELOG.md

@samdark samdark added the status:under development Someone is working on a pull request. label Jan 11, 2021
@ziaratban
Copy link
Contributor

i think it is not a good way, because a variety of mongodb connection string patterns exist.(Standalone & Replica Set & Shard).

the defaultDatabaseName parameter is required for better performance and compatibility.

https://docs.mongodb.com/manual/reference/connection-string/

@metola
Copy link
Author

metola commented Jan 17, 2021

Hi @ziaratban ,
what do you think is the best way to approach it?

@ziaratban
Copy link
Contributor

ziaratban commented Jan 18, 2021

hi @metola ,
I think the best solution is to not customize this part. this part must be set by programmer.

return [
    'class' => 'yii\mongodb\Connection',
    'dsn' => 'mongodb://any syntax',
    'defaultDatabaseName' => 'myDB', // <<<< required 
    'enableLogging' => YII_ENV === 'dev',
    'enableProfiling' => YII_ENV === 'dev',
];

@metola
Copy link
Author

metola commented Feb 6, 2021

Hi @ziaratban ,
Thanks, with this worlk well.

@metola metola closed this Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:under development Someone is working on a pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants