Failed to connect to mongodb server on google machine to calculate through my java code from my local machine

MongoClient mongo = new MongoClient("23.236.50.143",27017);
    System.out.print(mongo);
    List<String> dbs = mongo.getDatabaseNames();
    for(String db1 : dbs){
        System.out.println(db1);
}

23.236.50.143 - external ip of the instance of the computing mechanism.

I also added a firewall rule to allow connection by port number 27017.

It goes on Connection Refused Error.

What am I doing wrong?

+4
source share
1 answer

You mentioned that you added a firewall rule to connect to port 27017. Make sure you add this firewall rule to the control panel Google Cloud Consoleor using the command-line utility gcloud.

IP- , dahsboard Google Cloud Console.

Mongo ( /etc/mongod.conf), IP- bind_ip.

:

$ vim /etc/mongod.conf
# /etc/mongod.conf

# Listen to local interface only. Comment out to listen on all interfaces.
bind_ip = 127.0.0.1

IP- :

$ vim /etc/mongod.conf

# /etc/mongod.conf

# Listen to local and LAN interfaces.
bind_ip = 127.0.0.1,X.X.X.X

X.X.X.X - IP . mongo.

. IP- mongo.

: MKyong.com: MongoDB -

+3

All Articles