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

Inconsistent handling of mongodb:// URIs

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Minor - P4 Minor - P4
    • None
    • 4.0.25
    • None
    • None

    Description

      Description

      Attempting to use the mongodb URI "mongodb://0.0.0.0:27017/db" works with mongodump/mongorestore but fails with mongo shell.

      When running mongo inside a docker-compose environment, I would typically run "docker-compose port mongodb 27017" to get the address and port which docker mapped the docker container port to on the local host. Ie. it could respond with "0.0.0.0:49156".

       

      Example:

      MONGODB_URI="mongodb://$(docker-compose port mongodb 27017)/db"

      mongorestore --uri "$MONGODB_URI" --dir dump --drop

      mongo "$MONGODB_URI" database/transformMessages.js

       

      The last step fails however, which the error message below:

      MongoDB shell version v4.0.25
      connecting to: mongodb://0.0.0.0:49156/?gssapiServiceName=mongodb
      2021-06-17T11:55:16.488+0200 E QUERY [js] Error: couldn't connect to server 0.0.0.0:49156, address resolved to 0.0.0.0 :
      connect@src/mongo/shell/mongo.js:356:17
      @(connect):2:6
      exception: connect failed

       

      And just to confirm a connection is possible:

      curl -sv http://0.0.0.0:49156/

      • Trying 0.0.0.0:49156...
      • TCP_NODELAY set
      • Connected to 0.0.0.0 (127.0.0.1) port 49156 (#0)
        > GET / HTTP/1.1
        > Host: 0.0.0.0:49156
        > User-Agent: curl/7.68.0
        > Accept: /
        >
      • Mark bundle as not supporting multiuse
      • HTTP 1.0, assume close after body
        < HTTP/1.0 200 OK
        < Connection: close
        < Content-Type: text/plain
        < Content-Length: 85
        <
        It looks like you are trying to access MongoDB over HTTP on the native driver port.
      • Closing connection 0

       

      Steps to Reproduce

      1. docker run --rm -it -p 27017 --name mongo -d mongo

      2. MONGODB_URI="mongodb://$(docker port mongo 27017 | head -n1)/test"

      3. mongo "$MONGODB_URI"

       

       

      Attachments

        Activity

          People

            edwin.zhou@mongodb.com Edwin Zhou
            tais.hansen@gmail.com Tais P. Hansen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: