Reputation: 442
I am new to Mongo. I have installed mongo DB in my ubuntu desktop and start the mongod service using the following command -
sudo service mongod start
root@monti-ThinkPad-L440:/home/monti# sudo service mongod start
root@monti-ThinkPad-L440:/home/monti# sudo service mongod status
● mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: active (running) since Sat 2017-06-10 19:19:04 IST; 19s ago
Docs: https://docs.mongodb.org/manual
Main PID: 4407 (mongod)
CGroup: /system.slice/mongod.service
└─4407 /usr/bin/mongod --quiet --config /etc/mongod.conf
Jun 10 19:19:04 monti-ThinkPad-L440 systemd[1]: Started High-performance, schema-free document-oriented database.
but when I am starting mongo shell, I am gettign the following error:
root@monti-ThinkPad-L440:/home/monti# mongo
MongoDB shell version: 3.2.13
connecting to: test
2017-06-10T19:20:44.363+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2017-06-10T19:20:44.363+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6
exception: connect failed
Any help is VERY APPRECIATED!!!! Thanks!!!
Upvotes: 0
Views: 1388
Reputation: 46
You may need to change your bind_ip to 0.0.0.0 on /etc/mongod.conf You can't access your machine when you bind it to 127.0.0.1.
127.0.0.1 will only bind to the loopback interface (so you will only be able to access it locally), while 0.0.0.0 will bind it to all network interfaces that are reachable.
That's why you can access your mongodb when you bind it to 0.0.0.0 and not via 127.0.0.1.
Binding to 0.0.0.0 for local servers might make them available over all network interfaces.
In your firewall, you should make sure that you open 27017 only for people who has the rights to reach your MongoDB server: If you want to be more restrictive, change 0.0.0.0 by authorized range of IPs.
Example:
bindIp = [56.126.233.72, 172.29.19.240, 172.29.5.20/16]
Upvotes: 0
Reputation: 3272
There are lot of good and multiple answers to this question here:
Connection refused to MongoDB errno 111
One of this would solve your problem for sure.
Generally happens due to some misconfiguration in /etc/mongod.conf or a lock at /var/lib/mongodb/mongod.lock
Hope this helps !
Upvotes: 1