Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-1730

Connection string with "mongodb+srv" and port fails parsing

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.9.0
    • Component/s: None
    • None

      Take the following connection string:

      mongodb+srv://xxx.yyy.mongodb.net:27017
      

      This string works when used for connection from the command line:

      mongo 'mongodb+srv://catdev.jdx66.mongodb.net:27017'
      

      But when the same string is used to connect with the PHP driver, that fails:

      <?php
      require_once __DIR__ . '/vendor/autoload.php';
      
      new \MongoDB\Client('mongodb+srv://xxx.yyy.mongodb.net:27017');
      
      --
      
      PHP Fatal error:  Uncaught MongoDB\Driver\Exception\InvalidArgumentException: Failed to parse MongoDB URI: 'mongodb+srv://xxx.yyy.mongodb.net:27017'. Invalid service name in URI. in /vendor/mongodb/mongodb/src/Client.php:116
      

      I believe that connection string is correct as per the specification. I know 27017 is the default port but in general it may be different.

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            martin.melka@rohea.com Martin Melka
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: