mongo-php-driver: Unable to use mongodb+srv URI format
Description
I’m unable to use the URI string format mongo+srv
to connect to my MongoDB cluster.
Environment
Driver (1.4.2) and ext-mongodb (1.5.3) are latest versions available. PHP is a Docker container, starting from the official Alpine image:
$ php -v
PHP 7.3.3 (cli) (built: Mar 9 2019 01:29:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.3, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.3, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v2.7.0, Copyright (c) 2002-2019, by Derick Rethans
with blackfire v1.24.4~linux-musl-x64-non_zts73, https://blackfire.io, by Blackfire
$ php -i | grep -E 'mongodb|libmongoc|libbson'
/usr/local/etc/php/conf.d/docker-php-ext-mongodb.ini,
mongodb
libbson bundled version => 1.13.0
libmongoc bundled version => 1.13.0
libmongoc SSL => enabled
libmongoc SSL library => OpenSSL
libmongoc crypto => enabled
libmongoc crypto library => libcrypto
libmongoc crypto system profile => disabled
libmongoc SASL => enabled
libmongoc ICU => disabled
libmongoc compression => enabled
libmongoc compression snappy => disabled
libmongoc compression zlib => enabled
mongodb.debug => no value => no value
Test Script
<?php
require_once __DIR__ . '/vendor/autoload.php';
new \MongoDB\Client('mongodb+srv://mongo/');
Expected and Actual Behavior
Expected: no errors. Actual:
PHP Fatal error: Uncaught MongoDB\Driver\Exception\InvalidArgumentException: Failed to parse MongoDB URI: 'mongodb+srv://mongo/'. Invalid service name in URI. in /var/www/insight/core/vendor/mongodb/mongodb/src/Client.php:87
Stack trace:
#0 /var/www/insight/core/vendor/mongodb/mongodb/src/Client.php(87): MongoDB\Driver\Manager->__construct('mongodb+srv://m...', Array, Array)
#1 /var/www/insight/core/test.php(5): MongoDB\Client->__construct('mongodb+srv://m...')
#2 {main}
thrown in /var/www/insight/core/vendor/mongodb/mongodb/src/Client.php on line 87
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17 (9 by maintainers)
@jmikola I got corrected by my colleague, our DNS in fact HAS the trailing dot, so no blockers in our case for that! 👍
Thanks a lot for the thorough research!
As for adding the trailing dot on the SRV result, I’ll ask to my colleague who’s handling it and report back.