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

WindowsMongodbDatabaseNosql

Windows Problem Overview


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

Windows Solutions


Solution 1 - Windows

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 - Windows

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 - Windows

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 - Windows

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

Solution 5 - Windows

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

Solution 6 - Windows

Point to your mongodb instalation e.g C:\Program Files\MongoDB\Serve\bin and run mongod.exe so you can open connection to 127.0.0.1:27017.

Solution 7 - Windows

If it writes that you had not properly shut down or that mongod.lock is not empty , only delete mongod.lock from C:\data\db\ and it will start.

Solution 8 - Windows

Under normal conditions, at least 3379 MB of disk space is needed. If you do not have that much space, to lower this requirement;

mongod.exe --smallfiles

This is not the only requirement. But this may be your problem.

Solution 9 - Windows

The problem is that I missed out 'db' folder for the dbpath in the command:

C:\mongodb\bin> mongod --directoryperdb --dbpath C:\mongodb\data\db --logpath C:\mongodb\log\mongodb.log --logappend -rest --install

Solution 10 - Windows

What solved my issue was creating a file startmongo.conf that sets the bind_ip to 127.0.0.1 . After that, I just created a *.bat to start the mongo using something like:

mongod --config c:\mongodb\bin\startmongo.conf

Solution 11 - Windows

When This Error is Coming it is lack of the following

1)Setting the path to mongo db go to "C" Drive and the installation of Mongo db directory and then go to bin folder in the mongo and copy the path of it > c:/mongodb/server/3.2/bin/ and create a new environmental variable in system properties then name is path and value="c:/mongodb/server/3.2/bin/" here my version is 3.2

2)create a data directory for the data in C Drive c:/Data/twitter

3)start the server with **

>c:/> mongod

check your port config if there is any error as the local port may be assigned to any other 4)start your Mongo database with

> Mongo then your mongo db will start

then in your mongo database create a database

> use DATABASE_NAME

for example:

use twitterdata

switched to db twitterdata

to check your current database

> db

twitterdata

to get total databases

> show dbs

Solution 12 - Windows

I started mongod in cmd,It threw error like C:\data\db\ not found. Created folder then typed mongod opened another cmd typed mongo it worked.

Solution 13 - Windows

Here are the steps to solve this issue:

  1. Just go to your MongoDB bin folder and run the mongod.exe file.
  2. Navigate to your mongodb bin folder via Command prompt and start mongo by typing "mongo"

Solution 14 - Windows

Change file permission to 755 for the file:

/var/lib/mongodb/mongod.lock

Solution 15 - Windows

first you run the command mongod and check weather the port 27017 has started or not if yes then hit the command mongo....and database will start.

Solution 16 - Windows

The Port is not open. Thats why the machine refuses communication

Solution 17 - Windows

Try this, it worked for me.

mongod --storageEngine=mmpav1

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichaelView Question on Stackoverflow
Solution 1 - WindowsChee Loong SoonView Answer on Stackoverflow
Solution 2 - WindowsUrasquirrelView Answer on Stackoverflow
Solution 3 - WindowssonalView Answer on Stackoverflow
Solution 4 - WindowsmorecastView Answer on Stackoverflow
Solution 5 - WindowsShaik naseerView Answer on Stackoverflow
Solution 6 - WindowsZoran PandovskiView Answer on Stackoverflow
Solution 7 - WindowsAnticor MoldView Answer on Stackoverflow
Solution 8 - Windowsİsmail CeylanView Answer on Stackoverflow
Solution 9 - WindowsLekan StephenView Answer on Stackoverflow
Solution 10 - WindowsG.NaderView Answer on Stackoverflow
Solution 11 - WindowsPavan vadrevuView Answer on Stackoverflow
Solution 12 - Windowsuser6485832View Answer on Stackoverflow
Solution 13 - WindowsinspiredMichaelView Answer on Stackoverflow
Solution 14 - WindowsKrupal PatelView Answer on Stackoverflow
Solution 15 - WindowsJay KhalkhoView Answer on Stackoverflow
Solution 16 - WindowsEtixppView Answer on Stackoverflow
Solution 17 - Windowsuser6077898View Answer on Stackoverflow