Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (50.2k points)

My following implementation runs successfully if the host is localhost or 127.0.0.1:

conf.set( "mongo.input.uri" , "mongodb://127.0.0.1/flow.mrtest" );

conf.set( "mongo.output.uri" , "mongodb://127.0.0.1/flow.mrtest_out2" );

But when I changed it to IP wlan0 192.168.1.102, it gives me the error as follows:

Cluster created with settings {hosts=[192.168.1.102:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}

Exception in monitor thread while connecting to server 192.168.1.102:27017

com.mongodb.MongoSocketOpenException: Exception opening socket

    at com.mongodb.connection.SocketStream.open(SocketStream.java:63)

    at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)

    at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)

    at java.lang.Thread.run(Thread.java:745)

Caused by: java.net.ConnectException: connection refused

    at java.net.PlainSocketImpl.socketConnect(Native Method)

    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)

    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)

    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)

    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)

    at java.net.Socket.connect(Socket.java:589)

    at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)

    at com.mongodb.connection.SocketStream.open(SocketStream.java:58)

    ... 3 more

I have also opened the port 27017 and I am having Ubuntu 14.04. as my operating system.

sudo iptables -A INPUT -ptcp --dport 27017 -j ACCEPT

1 Answer

0 votes
by (107k points)
edited by

MongoDB by default connects to the loopback interface that causes it to only reachable from the localhost. You just have to add the following code in mongod.conf file:

# /etc/mongod.conf

# Listen to the local interface only. Comment out to listen on all interfaces.

bind_ip = 127.0.0.1

You can also switch your bind_ip to 127.0.0.1,192.168.1.102  for allowing the LAN and local connections.

Want to learn MongoDB from the experts, Check out this MongoDB Course in London to enhance your Knowledge!

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer
0 votes
2 answers
asked Oct 16, 2019 in Web Technology by Sammy (47.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...