Probably a duplicate here but was not able to find the correct answer hence asking the question.
So, I have a mongodb
setup on my local machine say M1
where the mongo service is running and db has some data.
Now, I want to connect to this mongodb using a mongo client on some other machine say M2
but not able to.
Following all the answers, I tried adding the M2
address in mongodb.conf
file but no luck.
net:
bindIp: [m2.some.valid.ip,127.0.0.1]
I even tried giving 0.0.0.0
but still no luck. With localhost, am able to connect from my own machine but if I mention M1
address and try locally with that address I get
Cannot connect to Mongo DB at M1 address, network is unreachable.
AM badly stuck for long here. Have just started with mongodb
so pardon for any newbie question.
All my mongo services are up and running and am able to access the data using terminal or any mongo client at localhost.
This is the log when i run command mongod
on terminal:
2018-09-11T11:14:13.977+0530 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] MongoDB starting : pid=11307 port=27017 dbpath=/data/db 64-bit host=DELC02S5E2CG8WN.sea.corp.expecn.com
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] db version v4.0.2
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] git version: fc1573ba18aee42f97a3bb13b67af7d837826b47
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] allocator: system
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] modules: none
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] build environment:
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] distarch: x86_64
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] target_arch: x86_64
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] options: {}
2018-09-11T11:14:13.993+0530 I STORAGE [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-09-11T11:14:13.993+0530 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=7680M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2018-09-11T11:14:14.698+0530 I STORAGE [initandlisten] WiredTiger message [1536644654:698414][11307:0x7fff8fb43380], txn-recover: Main recovery loop: starting at 2/7040
2018-09-11T11:14:14.792+0530 I STORAGE [initandlisten] WiredTiger message [1536644654:792304][11307:0x7fff8fb43380], txn-recover: Recovering log 2 through 3
2018-09-11T11:14:14.856+0530 I STORAGE [initandlisten] WiredTiger message [1536644654:856010][11307:0x7fff8fb43380], txn-recover: Recovering log 3 through 3
2018-09-11T11:14:14.904+0530 I STORAGE [initandlisten] WiredTiger message [1536644654:904754][11307:0x7fff8fb43380], txn-recover: Set global recovery timestamp: 0
2018-09-11T11:14:15.037+0530 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten]
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten]
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten]
2018-09-11T11:14:15.157+0530 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2018-09-11T11:14:15.161+0530 I NETWORK [initandlisten] waiting for connections on port 27017
mongodb version is db version v4.0.2
and am using mac.
Also, when I bind ip of my M2
machine, and do a mongo --host m2.address
, i get this:
mongo --host m2.address
MongoDB shell version v4.0.2
connecting to: mongodb://m2.address:27017/
2018-09-11T11:31:07.186+0530 E QUERY [js] Error: couldn't connect to server m2.address:27017, connection attempt failed: SocketException: Error connecting to m2.address:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:257:13
@(connect):1:6
exception: connect failed
UPDATE
These are the steps I perform before trying to connect:
- Start
mongodb
service: brew services start mongodb - Start
mongod
by running commandmongod
- Using Robo3T to create a connection by specifying
0.0.0.0
as connection address. Tried specific address as well. - All giving "Network Unreachable" error.
Let me know if am missing any parameters on start or if am doing anything wrong.