简体   繁体   English

Java mongodb连接到远程服务器

[英]Java mongodb connecion to remote server

I have amazon ec2 windows instance running, and i have associated elastic ip to it. 我正在运行Amazon EC2 Windows实例,并且我已经将它关联到了IP。 I have installed mongoDB on this instance. 我已经在此实例上安装了mongoDB。 When i try to connect to this remote mongodb database using java it gives me following error: 当我尝试使用Java连接到此远程mongodb数据库时,出现以下错误:

com.mongodb.DBTCPConnector initDirectConnection WARNING: Exception executing isMaster command on /54.200.155.174:27017 java.io.IOException: couldn't connect to [/54.200.155.174:27017] bc:java.net.SocketTimeoutException: connect timed out. com.mongodb.DBTCPConnector initDirectConnection警告:在/54.200.155.174:27017 java.io.IOException上执行isMaster命令的异常:无法连接到[/54.200.155.174:27017] bc:java.net.SocketTimeoutException:连接超时。

Mongodb version used is 2.0.7 and this is my connection code: 使用的Mongodb版本是2.0.7,这是我的连接代码:

try
    {
        Mongo mongo=new Mongo("54.200.155.174",27017);
        DB db=mongo.getDB("mydb");
        DBCollection coll=db.getCollection("users");
        DBCursor cursor=coll.find();
        DBObject db1;

        while(cursor.hasNext())
        {
            db1=cursor.next();
            Object o=db1.get("email_id");
            System.out.println("email:"+o.toString());
        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

This is a network issue. 这是网络问题。 Maybe there is some firewall? 也许有一些防火墙? Check if you can telnet to this ip and port. 检查是否可以telnet到该IP和端口。 Or check if you can ping it. 或检查是否可以ping

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM