yiisoft / yii2-mongodb

Yii 2 MongoDB extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
326 stars 191 forks source link

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

Closed metola closed 3 years ago

metola commented 3 years ago

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
samdark commented 3 years ago

Also need a line for CHANGELOG.md

ziaratban commented 3 years ago

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 commented 3 years ago

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

ziaratban commented 3 years ago

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 commented 3 years ago

Hi @ziaratban , Thanks, with this worlk well.