36
votes

After I have started Mongo using mongod.exe on a Windows 7 machine, I tried to start the mongo shell that failed with the 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.

...

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

In the CMD where I running the mongod the output is:

C:\Users\Vera>mongod --dbpath c:\mongodb\mongodata

2014-05-18T17:10:10.135-0300 [initandlisten] MongoDB starting : pid=3296 port=27017 dbpath=c:\mongodb\mongodata 64-bit host=Vera-PC

2014-05-18T17:10:10.136-0300 [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2

2014-05-18T17:10:10.136-0300 [initandlisten] db version v2.6.1

2014-05-18T17:10:10.136-0300 [initandlisten] git version: 4b95b086d2374bdcfcdf2249272fb552c9c726e8

2014-05-18T17:10:10.136-0300 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1')

BOOST_LIB_VERSION=1_49

2014-05-18T17:10:10.136-0300 [initandlisten] allocator: system

2014-05-18T17:10:10.136-0300 [initandlisten] options: { storage: { dbPath: "c:\mongodb\mongodata" } }

2014-05-18T17:10:10.242-0300 [initandlisten] journal dir=c:\mongodb\mongodata\journal

2014-05-18T17:10:10.243-0300 [initandlisten] recover : no journal files present, no recovery needed

2014-05-18T17:10:11.077-0300 [initandlisten] waiting for connections on port 27017

Any suggestion how to fix this issue?

16

16 Answers

38
votes

I got the same error and fixed it with:

1) mkdir c:\data

2) cd data

3) mongod -dbpath .

4) Now in another command window I was able to connect from my client using the mongo command.

23
votes

I got this problem. What fixed mine is:

  1. Suppose you have a dir: "C:\mongo_databse"
  2. Open Command Prompt and type (suppose you haved added the Mongo bin directory to PATH): mongod --dbpath=C:/mongo_database. There will be some log to the command prompt.

  3. Now open ANOTHER command prompt then type in mongo then it works.

10
votes

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

More details could be seem at this post .

7
votes
  1. I assume your mongo.config file to be located inside the mongodb folder in the same level to the bin directory.The contents of the mongo.config file are:

    dbpath=C:\mongodb\data
    logpath=C:\mongodb\log\mongo.log
    diaglog=3
    

    don't forget to create the data folder and log folder in the same level of bin directory inside log folder create the mongo.log empty file.

  2. Point your command prompt to C:\mongodb\bin wherever your mongo db bin folder is located.

  3. create the mongo db service in windows typing

    mongod.exe --storageEngine=mmapv1 --config=../mongo.config 
    
  4. from now unwards you can start the mongo db service as

    net start mongodb
    
  5. finally you can connect to the mongo db server from the mongo db client typing

    mongo.exe
    
  6. once you have gone successfully from step 1 to step 3 from the next time on wards you only need the step 4 and 5.to start the service and to connect.

3
votes

it prompted me like this

1)So, i created a path

C:\data\db

2)Now run

mongod in your terminal

it solved me issue!

2
votes

I got this error beacuse of not sufficient space in the disk. Check your mongo log.

2
votes

I was getting a similar error when I was trying to start my mongo db via cmd. However the difference was I had a config file which has the path to the db and log folders and wanted to use the same. I was using mongo few days back and it was running fine but when I started using it again today it was giving me the error :

2015-05-27T10:33:22.820-0400 I CONTROL  Hotfix KB2731284 or later update is   installed, no need to zero-out data files
MongoDB shell version: 3.0.2
connecting to: test
2015-05-27T10:33:23.854-0400 W NETWORK  Failed to connect to 27.0.0.1:27017, reason: errno:10061 No connection could be made because the target machine actively refused it.
2015-05-27T10:33:23.857-0400 E QUERY    Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at connect src/mongo/shell/mongo.js:179:14) at (connect):1:6 at src/mongo/shell/mongo.js:179 exception: connect failed

Here's how I fixed it :

  1. Open cmd as admin and navigate to the bin folder of your MongoDB and type : mongod --config <path to your config file> --install
  2. Now start your mongo db service : net start mongodb you should get a message which says : The MongoDB service was started successfully.
  3. close this command prompt and open another one as admin, navigate to the bin folder once again and type mongo

This will connect you to the mongodb test.

Press ctrl+c anytime to exit.

Hope this helps.

1
votes

Open task manager, click on the services tabs on the top. From the list right click on mongoDB then click start.

1
votes

In Windows 10: Executing below command restarts mongodb service (as administrator), required if there is a system restart after mongodb installation.

net start mongodb 

Also make sure to check, if there is a MongoDBInstallation folder/data and /data/db folder created, same can be obtained at MongoDBInstallation\bin\mongod.cfg

mongod --dbpath=c:\MongoDBInstallation\data\db
0
votes

I had a very similar experience to @user1501382, but tweaked everything slightly in accordance with the documentation

1) cd c: //changes to C drive

2) mkdir data //creates directory data

3) cd data

4) mkdir db //creates directory db

5) cd db //changes directory so that you are in c:/data/db

6) run mongod -dbpath

7) close this terminal, open a new one and run mongod

0
votes

for mongodb 3.0 versions use "--smallfiles".

e.g:-

mongod --dbpath="C:\Program Files\MongoDB\Server\3.0" --logpath="C:\Program Files\MongoDB\Server\3.0\data\log.txt" --smallfiles --install

0
votes

I am not sure if there is a better way to run it. For me, I use these settings to create a directory and to a determinate new path for the MongoDB. The important thing for me is that I miss to run it as a server (mongod) and after that into another terminal I type mongo which provide me an option to use the database. I hope this could help someone.

0
votes

I found my answer on this page. https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mongo-app?view=aspnetcore-3.1&tabs=visual-studio So, first, make a folder for your data; then, open one command shell

mongod --dbpath <data_directory_path>

then, open another shell, do whatever you want to do. You can see in MongoDB Compass, there are collections if you had one before.

0
votes

I tried the above answer , and it worked, but had a very important problem: My previous collections were lost in another mongoDB data folder which I didn't know where they are and how to get them back.

Before I run in to this mongo error, I was running mongo with no problem. When my windows10 boot files got corrupted and My computer went into blue screen, mongo ran into this error. So I just tried to retrieve the previous condition which I just was running mongo in one terminal and not mongod in another, so

I repaired mongoDB with it's installation exe file, and now everything is ok.

This is my mongoDB specs: mongodb-win32-x86_64-2012plus-4.2.1

Hope this help you too.

0
votes

Just type mongod in one command prompt and then run mongo in another.

0
votes

Simply follow the following steps mostly your problem will be solved(Windows 10) services->mongodb->change auto to run