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

MONGODB ATLAS CONNECTION ISSUE #452

Closed
miljojohn opened this issue Mar 2, 2018 · 10 comments · Fixed by alcaeus/mongo-php-adapter#222
Closed

MONGODB ATLAS CONNECTION ISSUE #452

miljojohn opened this issue Mar 2, 2018 · 10 comments · Fixed by alcaeus/mongo-php-adapter#222
Labels

Comments

@miljojohn
Copy link

I am trying to use mongodb atlas in my application.I set up my .env file like

###> doctrine/mongodb-odm-bundle ###
MONGODB_URL=mongodb+srv://testuser:yyyyxyxyyx@cluster0-xcz.mongodb.net
MONGODB_DB=db_XYZ
###< doctrine/mongodb-odm-bundle ###
But i got one uri parse error.
Failed to parse MongoDB URI: 'mongodb://mongodb+srv://xxxxx:yyyyyyyyy@cluster0-xyz.mongodb.net

Please help .

@miljojohn miljojohn reopened this Mar 2, 2018
@malarzm
Copy link
Member

malarzm commented Mar 2, 2018

Looking at examples in the documentation your URI looks weird.

@malarzm
Copy link
Member

malarzm commented Mar 2, 2018

Ok this seems like a bug then. At a glance I don't see anything in the bundle that would be prepending URI with additional mongodb://, can you please share what driver are you using? Is this legacy mongo or new mongodb + adapter?

@miljojohn
Copy link
Author

I am using 3.6 and i am able to connect the mongodb atlas using new MongoDB\Client

$con = new MongoDB\Client("mongodb+srv://testuser:testpassword@cluster0-324234.mongodb.net");
I am attaching the php file which is working perfectly .
phpconnection.txt

From symfony i tried with the connection string for 3.4 mongodb version and its working fine.

Thanks a lot.

@malarzm
Copy link
Member

malarzm commented Mar 2, 2018

Ok, found the issue in the adapter, gonna open an issue there and cross reference.

@alcaeus
Copy link
Member

alcaeus commented Mar 5, 2018

@miljojohn would you mind testing dev-master of mongo-php-adapter? I've merged the changes and will tag a new release later today.

@alcaeus
Copy link
Member

alcaeus commented Mar 5, 2018

@miljojohn the 1.1.5 release of mongo-php-adapter fixes the handling of mongodb+srv connection URLs. If the problem persists, please open an issue there. Thanks!

@alcaeus
Copy link
Member

alcaeus commented Mar 6, 2018

While not good, the error points out that ext-mongodb was built without SSL support. How did you install the driver?

@miljojohn
Copy link
Author

pecl install mongodb
$ echo "extension=mongodb.so" >> php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"

Installed ext-mongodb using this command and also i am able to connect the atlas server from normal php on the same server. Please refer this code https://github.com/doctrine/DoctrineMongoDBBundle/files/1774462/phpconnection.txt

@jmikola
Copy link
Member

jmikola commented Mar 7, 2018

The exception with message "Cannot create SSL client. SSL is not enabled in this build." originates in phongo_manager_init() when MONGOC_ENABLE_SSL is not defined.

In the same file, PHP_MINFO_FUNCTION(mongodb) also checks whether MONGOC_ENABLE_SSL is defined to report "libmongoc SSL" for phpinfo() output.

The formatting of the phpinfo() output you've shared numerous times in this thread indicates that you obtained it from a CLI process. I'm reasonably certain that if you checked the phpinfo() output from the same PHP environment that is yielding the "Cannot create SSL client." error, you'd find that "libmongoc SSL" is not enabled.

It's entirely possible to have multiple versions of PHP installed on the same system. This is often the case for MacOS users, where they might have the default version of PHP that ships with MacOS, a version available with MAMP, and/or a PHP runtime installed with Homebrew. In the future, this is all helpful information that you should provide in a support request. AFAIK, you've provided no details whatsoever about your operating system or PHP environment.

pecl install mongodb
echo "extension=mongodb.so" >> php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"

The second line in the command above is only adding "extension=mongodb.so" to the INI file used by the php CLI command. You should understand that each PHP SAPI (e.g. CLI, web) may have its own INI file, which will need "extension=mongodb.so" added to function properly.

I assume you copied that snippet from the PHP library or driver README files. Both of those also link to Installing the MongoDB PHP Driver with PECL on PHP.net, which talks about each PHP environment possibly having its own pecl command and php.ini files.

You should confirm exactly which PHP environment is producing this exception, and then walk through installation steps for that exact environment. Assuming that environment has its own pecl command and php.ini file, those should be used for installation.

@miljojohn
Copy link
Author

thank you @jmikola . Issue is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants