我正在尝试使用此代码将本地java应用程序连接到openshift MongoDB
String mongoUri = "mongodb://admin:password@myServerIP:27017/";
MongoClient mongoClient;
mongoClient = new MongoClient(new MongoClientURI(mongoUri));
DB db = mongoClient.getDB("mongo");
System.out.println("Successfully connected to MongoDB ");
但它连接到本地机器MongDB?它给我这个错误?
com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=remoteIpAddress:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.ConnectException: Connection refused: connect}}]
我正在搜索,我找到了解决方案(端口转发),但我不能这样做,任何人都给我解决方案,谢谢。