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

Not able to connect mongo db on ec2 server from standalone Java program

    • Type: Icon: Task Task
    • Resolution: Incomplete
    • Priority: Icon: Blocker - P1 Blocker - P1
    • None
    • Affects Version/s: 2.4
    • Component/s: Authentication
    • Environment:
      Amazon ec2 server

      Hi All,
      I have installed mongo db on amazon ec2 server, I am trying to connect the db from my local java standalone program. But it throwing exception, I know there is a firewall issue on my server. I am new this amazon ec2 and mongo db. Could anybody help me to resolve this issue?

      Here is error I am getting when I run the program from my local machine...

      Nov 08, 2013 7:14:04 AM com.mongodb.DBTCPConnector initDirectConnection
      WARNING: Exception executing isMaster command on ec2-XX-XXX-XX-XX.compute-1.amazonaws.com/XX.XXX.XX.XX:27017
      java.io.IOException: couldn't connect to [ec2-XX-XXX-XX-XX.compute-1.amazonaws.com/XX.XXX.XX.XX:27017] bc:java.net.SocketTimeoutException: connect timed out
      at com.mongodb.DBPort._open(DBPort.java:214)
      at com.mongodb.DBPort.go(DBPort.java:107)
      at com.mongodb.DBPort.go(DBPort.java:88)
      at com.mongodb.DBPort.findOne(DBPort.java:143)
      at com.mongodb.DBPort.runCommand(DBPort.java:148)
      at com.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:548)
      at com.mongodb.DBTCPConnector.isMongosConnection(DBTCPConnector.java:372)
      at com.mongodb.Mongo.isMongosConnection(Mongo.java:627)
      at com.mongodb.DB.wrapCommand(DB.java:294)
      at com.mongodb.DB.command(DB.java:272)
      at com.mongodb.DB.command(DB.java:256)
      at com.mongodb.DB.command(DB.java:313)
      at com.mongodb.DB.command(DB.java:211)
      at com.mongodb.DB.command(DB.java:326)

      Here is my java program:

      public static void main(String[] args) throws UnknownHostException {
      Mongo m = new Mongo("ec2-XX-XXX-XX-XX.compute-1.amazonaws.com/XX.XXX.XX.XX:27017");
      try

      { m.getDB("admin").command("ping"); }

      catch (MongoException.Network e)

      { // You should get this exception if the server is unavailable e.printStackTrace(); }

      }
      Note: I can able to connect mongo db from my terminal using ssh -i key-pair user@servername

      Could you please tell where to change the firewall setting in amazon ec2 server/is there anything has to do in my local machine?

      Thanks,
      Rengith Manickam

            Assignee:
            Unassigned Unassigned
            Reporter:
            rengith rengith manickam
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: