yii2-mongodb icon indicating copy to clipboard operation
yii2-mongodb copied to clipboard

Mongodb SRV not supported

Open tahpot opened this issue 6 years ago • 3 comments

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.

tahpot avatar Sep 12 '19 01:09 tahpot

Does it work if regex is fixed? If so, do you want to do a pull request?

samdark avatar Sep 12 '19 08:09 samdark

@samdark it does not, as then it fails on the Native PHP driver for some reason after that...

ndobromirov avatar Mar 20 '20 15:03 ndobromirov

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',
],

squio avatar May 18 '23 22:05 squio