Cannot connect to mongodb errno:61 Connection refused

前端 未结 13 1259
心在旅途
心在旅途 2020-12-04 05:38

I recently installed mongodb-2.6.0 with Homebrew. After successfully installed, I tried to connect using the mongo command. I am receiving the following errors

相关标签:
13条回答
  • 2020-12-04 06:09

    I encountered the exact same issue and here is a clear step by step process to avoid this error.

    Step 1 - Installation ( Don't follow this step if you have already installed MongoDB ):

    brew update
    brew install mongodb
    

    Step 2 - Run Mongo Daemon:

    mkdir -p /data/db
    sudo mongod
    

    Step 3 - Run Mongo Shell Interface:

    mongo
    

    In this sequence, I was able to run the mongo command without any error. I have also detailed the error trace and its solution on this blog.

    0 讨论(0)
  • 2020-12-04 06:09

    For anyone who is here looking for the answer for this after your mac has updated to OS Catalina

    run

    brew services start mongodb-community
    
    

    find more info here: https://medium.com/@semmons245/arghhhh-thanks-to-the-catalina-os-update-this-now-needs-changing-987f416ebcbe

    0 讨论(0)
  • 2020-12-04 06:09

    My guess is that you do not have a running database while trying to access testing through the "mongo" command.

    First run this command in terminal:

    mongod 
    

    Then open another terminal window and run:

    mongo

    Everything should be working now.

    0 讨论(0)
  • 2020-12-04 06:11

    I had the same issue and in looking in the log file I saw this:

    {2019-03-09T11:57:32.136-0500 I STORAGE  [initandlisten] 
    exception in initAndListen: NonExistentPath: 
    Data directory /usr/local/var/mongodb not found., terminating}
    

    so I created the directory /usr/local/var/mongodb issued the brew services restart mongodb command I was able to open the mongo console.

    0 讨论(0)
  • 2020-12-04 06:14

    I had the same error but a different root cause. Thought I'd post the solution here in case anyone else runs into the problem. I got this error after my Mac improperly shut down while I was running mongorestore -d foo dump/foo/.

    tl;dr: I fixed the problem by removing the damaged foo.ns file along with foo.0, foo.1,... from my data folder /usr/local/var/mongodb/. Then I restarted the mongo server with brew services restart mongodb and I was back to normal.

    Details: I kept getting the error even after trying to start or restart the mongodb service via brew or launchctl. Eventually I ran mongod --dbpath /usr/local/var/mongodb and saw that the service was not actually starting, and the start sequence included the following error: [initandlisten] bad .ns file: /usr/local/var/mongodb/foo.ns [initandlisten] User Assertion: 10079:bad .ns file length, cannot open database I got rid of the bad .ns file and the rest of the data files, and the next time I started the service I was good to go.

    0 讨论(0)
  • 2020-12-04 06:16

    I got this error after I upgraded to mongo 3.6 with homebrew.

    The log /usr/local/var/log/mongodb/mongo.log contained the message shutting down with code:62. This error code means that the existing database is too old to run with the current version of mongo.

    I found 2 solutions in another SO question:

    • Delete your database folder (/usr/local/var/mongodb)
    • Or follow the upgrade procedure

    I chose to upgrade. In my case, that meant I had to downgrade to 3.4, run a command in the mongo console, then upgrade again. Mongo requires you to upgrade one major version at a time, so depending on how far back you were, there could be additional steps. The docs will guide you.

    The brew switch * and brew services restart commands made swapping between versions relatively painless.

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