0
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
2018-10-01T17:38:22.425+0000 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-10-01T17:38:22.426+0000 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed

I get an error when I try to run mongo on the terminal. I tried to reinstall and removed lock file and restarted it, but It still doesn't work. I am using AWS, is it some problem about inbound, outbound of network setting in AWS, Or any other problem?

Scott Kim
  • 233
  • 1
  • 4
  • 13
  • 1
    you try to connect from your terminal, or in ssh from aws terminal? – matthPen Oct 01 '18 at 18:43
  • If you're running that command on the host that's running the mongodb daemon, then it can't be any AWS setting. If you're not running it on the same host, then your problem is the IP address is wrong. Can you clarify where you're running the terminal and where the service is? – Paul Oct 01 '18 at 21:12

1 Answers1

0

Like the comments above, if you are trying to connect to a mongodb instance on the same host, using 127.0.0.1 it is a mongodb configuration problem, so, that is not possible to be any AWS Security Rules.

So, considering it is a mongodb problem, first try to repair it inside the host with:

sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair
sudo service mongodb restart
sudo service mongod status

Refer: https://stackoverflow.com/a/29083477/8407784

After resolved the mongodb config problem, you need to test your connection from another host, setting /etc/mongod.conf - bind_ip = 0.0.0.0 (that means all interfaces), only for testing

Then you need to set your AWS Security Rules on the host instance allowing the external instance to access it on port 27017.

Roberto Gonçalves
  • 3,186
  • 4
  • 13
  • 27