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

mongo connection URI cannot connect when there's "@" character in password

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • Labels:
      None
    • Fully Compatible
    • ALL

      There is a "@" character in my password and I tried to use connection string URI to connect MongoDB

      mongo 'mongodb://user:abc@123@localhost:27017'

      And I get this error:

      ~➜ ~ mongo 'mongodb://da:abc@123@localhost:27017'
      MongoDB shell version v3.4.0
      connecting to: mongodb://da:abc@123@localhost:27017
      2017-02-14T15:02:59.061+0800 I NETWORK [main] getaddrinfo("123@localhost") failed: nodename nor servname provided, or not known
      2017-02-14T15:02:59.063+0800 E QUERY [main] Error: couldn't initialize connection to host 123@localhost, address is invalid :
      connect@src/mongo/shell/mongo.js:234:13
      @(connect):1:6
      exception: connect failed~

      But mongo admin -u da -p 'abc@123' works well.So I read the mongo shell and mongo-cxx-driver code and I found this:

      ~namespace

      { const char kMongoDBURL[] = // scheme: non-capturing "mongodb://" // credentials: two inner captures for user and password "(?:([^:]+)(?::([^@]+))?@)?" // servers: grabs all host:port or UNIX socket names "((?:(?:[^\\/]+|/.+.sock?),?)+)" // database: matches anything but the chars that cannot // be part of a MongoDB database name. "(?:/([^/\\.\\ \"*<>:\\|\\?]*))?" // options "(?:\\?(?:(.+=.+)&?)+)*"; }

      // namespace~

      So it means that if my connection URI is

      mongo 'mongodb://user:abc@123@localhost:27017'

      it will return mongodb://da1:abc@ rather than mongodb://da1:abc@123@ ,is it a bug or I missed something?

      Thanks.

            Assignee:
            spencer.jackson@mongodb.com Spencer Jackson
            Reporter:
            tracyda tracy
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: