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

Non-suppoted protocol mongodb+srv #304

Open
ndobromirov opened this issue Mar 20, 2020 · 1 comment
Open

Non-suppoted protocol mongodb+srv #304

ndobromirov opened this issue Mar 20, 2020 · 1 comment
Labels
status:ready for adoption Feel free to implement this issue.

Comments

@ndobromirov
Copy link

ndobromirov commented Mar 20, 2020

if (preg_match('/^mongodb:\\/\\/.+\\/([^?&]+)/s', $this->dsn, $matches)) {

The recommended protocol for connection DSNs in some cloud providers is: mongodb+srv
This is failing with an exception that a default database can not be found.

After setting the default database maually I am getting the following issue:

MongoDB\Driver\Exception\InvalidArgumentException: Failed to parse MongoDB URI: 'mongodb+srv://user:password@host/database'. 
Invalid URI Schema, expecting 'mongodb://'. in /var/www/html/web/vendor/yiisoft/yii2-mongodb/src/Connection.php:356

I am considering this a bug, as the official MongoDB connection library supports this and it's highly logical for this to be a thin wrapper around it. See PHP example here:

https://docs.atlas.mongodb.com/driver-connection/#driver-examples
@LLabsAaron
Copy link

Temporary workaround for anyone else experiencing this issue is to change it to:
if (preg_match('/^mongodb(:|\+srv:)\\/\\/.+\\/([^?&]+)/s', $this->dsn, $matches)) {

@samdark samdark added this to the 2.1.10 milestone Jul 14, 2020
@samdark samdark added the status:ready for adoption Feel free to implement this issue. label Jul 14, 2020
@samdark samdark modified the milestones: 2.1.10, 2.1.11 Nov 10, 2020
@samdark samdark modified the milestones: 2.1.11, 2.1.12 Dec 23, 2020
metola added a commit to metola/yii2-mongodb that referenced this issue Jan 10, 2021
@samdark samdark removed this from the 2.1.12 milestone Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for adoption Feel free to implement this issue.
Projects
None yet
Development

No branches or pull requests

3 participants