Mongodb: Failed to connect to 127.0.0.1:27017, reason: errno:10061

155,549

Solution 1

This is how I solved it, You can follow step by step here:

MongoDB Steps:

  • Download the latest 64-bit MSI version of MongoDB for Windows.

  • Run the installer (.msi file)

  • Add it to your PATH of environment variables. it Should be from:
    C:\Program Files\MongoDB\Server\3.0\bin

now Create a “\data\db” folder in C:/ which is used by mongodb to store all data. You should have this folder:

C:\data\db

Note: This is the default directory location expected by mongoDB, don’t create anywhere else

.

Finally, open command prompt and type:

>> mongod

You should see it asking for permissions (allow it) and then listen to a port. After that is done, open another command prompt, leaving the previous one running the server.

Type in the new command prompt

>> mongo

You should see it display the version and connect to a test database.

This proves successful install!=)

Reference link

Solution 2

When you typed in the mongod command, did you also give it a path? This is usually the issue. You don't have to bother with the conf file. simply type

mongod --dbpath="put your path to where you want it to save the working area for your database here!! without these silly quotations marks I may also add!"

example: mongod --dbpath=C:/Users/kyles2/Desktop/DEV/mongodb/data

That is my path and don't forget if on windows to flip the slashes forward if you copied it from the or it won't work!

Solution 3

I was also faced the same issue with mongodb 2.6.

What solved my problem was I just run mongod --repair command

and then start mongod.exe

It's worked for me

Solution 4

mongodb 2.6.8 on windows7 32bits you only need create a folder c:/data/db execute mongod, and execute mongo

Solution 5

just create a folder

C:\data\db 

Run below commands in command prompt

C:\Program Files\MongoDB\Server\3.4\bin>mongod

Open another command prompt

C:\Program Files\MongoDB\Server\3.4\bin>mongo
Share:
155,549
Michael
Author by

Michael

Updated on July 08, 2022

Comments

  • Michael
    Michael almost 2 years

    Here is my mongod.cfg file:

    bind_ip = 127.0.0.1
    dbpath = C:\mongodb\data\db
    logpath = C:\mongodb\log\mongo-server.log
    verbose=v
    

    Here is my mongod service command:

    mongod -f c:\mongodb\mongod.cfg --install
    

    I have installed MongoDB about a week ago and it all worked fine, however today when I ran mongo command I got the following error:

    Failed to connect to 127.0.0.1:27017,
    reason: errno:10061 No connection could be made because the target machine actively refused it
    

    How can I fix that? I use Windows 8.1

    Solution:

    I forgot to start mongodb service with this command:

    net start mongodb
    

    Improved solution:

    1) Change directory to root drive C:\, and type the command below into an admin cmd prompt window,

    C:\mongodb\bin\mongod.exe --config c:\mongodb\mongod.cfg --install
    

    2) Then type net start MongoDB after which you should see the following message:

    "The Mongo DB service was started successfully"
    

    3) Then go to the control panel Start>Administrative Tools>Services, scroll down to MongoDB in the list of services and change start up type to automatic, if you so desire. Press OK.

    4) Finally type C:\mongodb\bin\mongo.exe and you should be connected to the Mongo test DB.

    Reference: https://www.youtube.com/watch?v=-mik4dPArCU

  • Sithu
    Sithu over 9 years
    I wonder this is exactly the same as that answer.
  • dudewad
    dudewad about 9 years
    well, not exactly the same. This one is way newer. And it doesn't give credit to (both) of the sources of information. ;)
  • Jorgesys
    Jorgesys almost 9 years
    hey this a tutorial for mongo installation :o! I have the error described on this question, but reinstall i don´t think would be a good solution.
  • Chee Loong Soon
    Chee Loong Soon almost 9 years
    It was a solution that worked for me. By re-installing.
  • Frank Nocke
    Frank Nocke over 8 years
    No need for a batch btw, since (as of Jan '16, Version 3.2) the mongodb service is set to automatic (startup after boot). If you wanted to change that sc config "mongodb" start= demand
  • scottysseus
    scottysseus over 8 years
    This is what worked for me. Specifically, i ran mongod --dbpath=C:\data\db. You might notice that the C:\data\db is the default folder for the data storage mentioned in @morecast answer and @Chee Loong Soon answer
  • ρяσѕρєя K
    ρяσѕρєя K about 8 years
    This should be a comment
  • Abhishek Ghosh
    Abhishek Ghosh over 7 years
    This worked for me! I had to give it a --dbpath to mongod command and then ran mongo in a different shell and it worked!
  • Dee J.
    Dee J. over 7 years
    This helped me as well, especially that note about the directory location. Thanks!
  • Noorus Khan
    Noorus Khan almost 4 years
    worked for me ( mongod --dbpath=C:\data\db ) then inanother cmd run mongo command
  • Abhishek
    Abhishek over 3 years
    worked for me as well after trying for an hour