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

后端 未结 17 923
不知归路
不知归路 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
    > 
    
    0 讨论(0)
  • 2021-02-02 15:16

    This is due to locking of Mongodb
    sudo rm /var/lib/mongodb/mongod.lock
    sudo service mongodb restart

    0 讨论(0)
  • 2021-02-02 15:20

    If any one is facing the problem in windows machine then follow the steps.

    1. Add the path of mongodb in the environmental variable.
    2. Create a directory C:\Data\db.
    3. Open a terminal(cmd) and write mongod. (it will initiate the server).
    4. Open another terminal and write your own code.
    0 讨论(0)
  • 2021-02-02 15:20

    I met with this problem too. And I figured it out by the following way:

    First, open the terminal and write

    mongod --dbpath {your project's path}
    

    Second, open a new terminal and enter your project's path, write

    mongo
    

    Then it runs successfully

    0 讨论(0)
  • 2021-02-02 15:21

    with new version of mongodb, this issue got resolved.

    0 讨论(0)
提交回复
热议问题