Unable to connect to mongodb Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112

后端 未结 17 927
不知归路
不知归路 2021-02-02 14:45

When ever I try to connect to mongo db I always get this error as below.

MongoDB shell version: 2.4.3 connecting to: test Fri Apr 26 14:31:46.941 JavaScript execution f

17条回答
  •  借酒劲吻你
    2021-02-02 15:15

    I had the same issue, In my case there was a mismatch of ipaddress in mongo config

    ~# mongo
    MongoDB shell version: 2.6.7
    connecting to: test
    2015-02-02T17:48:52.302+0530 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
    2015-02-02T17:48:52.303+0530 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
    exception: connect failed
    

    When I checked my configuration file, I have specified the bind address to eth0 ip(10.8.10.111) not loopback address(127.0.0.1), So I have changed the ip address to loopback as like bind_ip = 127.0.0.1 in /etc/mongod.conf file and restart it with service mongod restart, finally works

    # mongo 
    MongoDB shell version: 2.6.7
    connecting to: test
    > 
    

提交回复
热议问题