Connection to mongodb://localhost:27017 gets UnknownHostException if machine's hostname doesn't resolve

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Environment:
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      If the machine's hostname does not resolve, then the following line will cause an UnknownHostException:
      ServerAddress sa=new ServerAddress("mongodb://localhost:27017");

      That's because the constructor for ServerAddress recognises the string "localhost" and calls InetAddress.getLocalHost(). This issue does not occur if you use "127.0.0.1" instead of "localhost".

      If you feel this is intended behavior, would you consider noting it in the documentation.

              Assignee:
              Unassigned
              Reporter:
              John Feibusch
              None
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: