Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-430

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

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

      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 Unassigned
            Reporter:
            jfeibusc@ebay.com John Feibusch
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: