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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • None
    • None

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jfeibusc@ebay.com John Feibusch
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: