2

I have turn on the port-forward with rhc, it shows mongodb 127.0.0.1:27017 => xxx.x.xxx.x:27017 doc here port-forward

but I still have no luck connect to that mongodb cartridge. I've try both mongo shell 3.0 and java MongoClient. mongo shell return error 10061 java return com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}

what else could I try to connect to openshift mongodb remotely?

my code, I've test this on local mongodb which works fine

    String mongoUri = "mongodb://admin:password@xxx.x.xxx.x:27017/";                        
    MongoClient mongoClient;
    try {

        mongoClient = new MongoClient(new MongoClientURI(mongoUri));

        DB db = mongoClient.getDB("mycoll");

        DBCollection cc = db.getCollection("DBObject");
        cc.insert(dbo);
    }
Maxi Wu
  • 1,274
  • 3
  • 20
  • 38

1 Answers1

0

You should be using the following connection string locally while you have port forwarding enabled:

String mongoUri = "mongodb://admin:password@127.0.0.1:27017/";

Since the connection is being forwarded over an ssh tunnel, you need to use the local port. See this answer for more information: OpenShift: How to connect to postgresql from my PC

Community
  • 1
  • 1
  • connecting locally is working, but what I want is to connect remotely. – Maxi Wu Jan 14 '16 at 09:14
  • You will be connecting remotely, that ip/port that shows up when you do a port forward gets forwarded to the remote server. –  Jan 14 '16 at 17:30
  • that's what I thought, but when I actually run my code, it gives me errno 10061 – Maxi Wu Jan 15 '16 at 08:22