Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-32396

mongo shell failed to connect with 3.6 connection string SRV

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.2, 3.7.1
    • Affects Version/s: 3.6.0
    • Component/s: Shell
    • None
    • Fully Compatible
    • ALL
    • v3.6
    • Hide

      1. Create/Open MongoDB Atlas Free Tier cluster
      2. Go to "Connect with the Mongo Shell" section, and choose "I am using shell 3.6. or later"
      3. Paste the mongo shell command.

      Show
      1. Create/Open MongoDB Atlas Free Tier cluster 2. Go to "Connect with the Mongo Shell" section, and choose "I am using shell 3.6. or later" 3. Paste the mongo shell command.
    • Platforms 2018-01-01

      Failed to connect using mongo shell to MongoDB Atlas (M0 Free Tier) using the new 3.6. connection URI.

      Currently in MongoDB Atlas a user is provided with two option to connect, shell 3.6 or later and shell 3.4. or earlier.

      Using mongo shell version 3.6.0 and 3.6.1-rc0, returns below:

      > mongo "mongodb+srv://servername-nesbp.mongodb.net/test" --authenticationDatabase admin --username <username> --password <password>
      MongoDB shell version v3.6.0
      connecting to: mongodb+srv://servername-nesbp.mongodb.net/test
      2017-12-19T11:12:58.990+1100 I NETWORK  [thread1] Starting new replica set monitor for servername-shard-0/servername-shard-00-00-nesbp.mongodb.net.:27017,servername-shard-00-01-nesbp.mongodb.net.:27017,servername-shard-00-02-nesbp.mongodb.net.:27017
      2017-12-19T11:13:01.460+1100 W NETWORK  [thread1] Unable to reach primary for set servername-shard-0
      2017-12-19T11:13:01.461+1100 I NETWORK  [thread1] Cannot reach any nodes for set servername-shard-0. Please check network connectivity and the status of the set. This has happened for 1 checks in a row.
      

      Also tried a different format of mongo "mongodb+srv://<username>:<password>@servername-nesbp.mongodb.net/test" --authenticationDatabase admin with no success.

      You can observe in the 'starting new replica set monitor' message when using the DNS lookup (3.6 SRV), it returns an extra dot (FQDN). May or may not be related SERVER-31965

      However, using the alternative URI version 3.4 or earlier works:

      > mongo "mongodb://servername-shard-00-00-nesbp.mongodb.net:27017,servername-shard-00-01-nesbp.mongodb.net:27017,servername-shard-00-02-nesbp.mongodb.net:27017/admin?ssl=true&replicaSet=servername-shard-0" --username <username> --password <password>
      MongoDB shell version v3.6.0
      connecting to: mongodb://servername-shard-00-00-nesbp.mongodb.net:27017,servername-shard-00-01-nesbp.mongodb.net:27017,servername-shard-00-02-nesbp.mongodb.net:27017/admin?ssl=true&replicaSet=servername-shard-0
      2017-12-19T11:19:24.884+1100 I NETWORK  [thread1] Starting new replica set monitor for servername-shard-0/servername-shard-00-00-nesbp.mongodb.net:27017,servername-shard-00-01-nesbp.mongodb.net:27017,servername-shard-00-02-nesbp.mongodb.net:27017
      2017-12-19T11:19:26.318+1100 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to servername-shard-00-02-nesbp.mongodb.net:27017 (1 connections now open to servername-shard-00-02-nesbp.mongodb.net:27017 with a 5 second timeout)
      

      Testing the same SRV connection using PyMongo v3.6 works fine.

      import pymongo 
      mongouri = "mongodb+srv://<username>:<password>@servername-nesbp.mongodb.net/test"
      client = pymongo.MongoClient(mongouri)
      collection = client.test.atlas 
      cursor = collection.find()
      for doc in cursor: 
          print(doc)
      

      Looking at the Python driver code, it omits the final dot before returning hosts
      https://github.com/mongodb/mongo-python-driver/blob/3.6.0/pymongo/uri_parser.py#L290

      Compared to mongo shell code:
      https://github.com/mongodb/mongo/blob/r3.6.1-rc0/src/mongo/client/mongo_uri.cpp#L378

            Assignee:
            adam.martin@mongodb.com ADAM Martin (Inactive)
            Reporter:
            wan.bachtiar@mongodb.com Wan Bachtiar
            Votes:
            0 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:
              Resolved: