yii2-mongodb
yii2-mongodb copied to clipboard
Mongodb SRV not supported
MongoDB supports SRV DSN format (https://www.mongodb.com/blog/post/mongodb-3-6-here-to-SRV-you-with-easier-replica-set-connections) since v3.6
In yii2-mongodb/src/Connection.php there's a regex expecting mongodb://, whereas the new format is mongodb+srv://, so this regex fails.
Does it work if regex is fixed? If so, do you want to do a pull request?
@samdark it does not, as then it fails on the Native PHP driver for some reason after that...
This regex is only used to parse the default database name when it is not set; the work around is to simply provide a defaultDatabaseName in the configuration in config.php:
'mongodb' => [
'class' => '\yii\mongodb\Connection',
'dsn' => 'mongodb+srv://user:[email protected]/?retryWrites=true&w=majority',
'defaultDatabaseName' => 'my_database',
],