MongoDB on a Windows 7 machine: No connection could be made
Asked Answered
G

20

37

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?

Girondist answered 18/5, 2014 at 20:45 Comment(0)
G
10

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 .

Girondist answered 24/5, 2014 at 5:31 Comment(0)
C
42

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.

Canara answered 5/10, 2014 at 16:14 Comment(4)
Thanks , this worked form me as : 'mkdir c:\data' , 'mongod -dbpath c:\data' Finally mongo in new cmd instanceTallou
For future users, there is a period after a space on #3 passing in the current path. Should be obvious, but still costed me a minute, could see someone getting hung up.Caen
Suggestion to the mongodb team: create this default data directory for us upon installation.Move
it works for me, I can start mongo now but I lost the previous data. Anyone know how to retrieve back the old data?Calv
M
25

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.

Mateya answered 6/2, 2015 at 7:27 Comment(0)
G
10

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 .

Girondist answered 24/5, 2014 at 5:31 Comment(0)
L
7
  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.

Lohr answered 17/12, 2015 at 9:59 Comment(1)
step 3, needs to be appended with switch --install to install the serviceCarrick
L
3

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!

Lewislewisite answered 21/3, 2020 at 10:1 Comment(0)
F
2

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

Ferial answered 19/7, 2014 at 19:23 Comment(0)
H
2

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.

Hylton answered 27/5, 2015 at 14:50 Comment(0)
R
2

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
Rikki answered 28/9, 2020 at 4:43 Comment(0)
A
1

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

Anomie answered 11/8, 2020 at 4:56 Comment(0)
C
0

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

Chagres answered 18/2, 2015 at 20:29 Comment(0)
C
0

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

Clio answered 24/10, 2015 at 17:37 Comment(0)
T
0

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.

Tsuda answered 24/5, 2019 at 5:54 Comment(0)
S
0

I found my answer on this page. https://learn.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.

Sprag answered 8/5, 2020 at 0:3 Comment(0)
D
0

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.

Dichotomy answered 22/10, 2020 at 9:10 Comment(0)
F
0

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

Furthermost answered 19/12, 2020 at 4:19 Comment(0)
A
0

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

Appellee answered 20/6, 2021 at 5:49 Comment(0)
C
0

you can go to services>>Mongo DB server .. right click and press start . This worked for me

Capps answered 27/11, 2021 at 7:11 Comment(0)
P
0

By simple step ,I was resolve this problem first step - make a New folder in C-drive in PC with name - "data" second step- now open this "data" folder Third step - Inside the "data" folder, again make a new "db" folder Note - Just leave it this both folder empty, no need to add any content inside this, and run "mongo" and "mongod" in PowerShell of your PC.

Pelt answered 30/12, 2021 at 6:4 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Theressathereto
S
0

I got the same error, and this is how I resolved it,

follow the below steps:-

  1. Open mongod.cfg file

  2. Add the bindIpAll: true tag in the net (Network Interfaces) section

  3. restart the mongoDB services.

    # network interfaces
    net:
      port: 27017
      bindIpAll: true
      #bindIp: 127.0.0.1
    
Sheya answered 18/11, 2022 at 8:36 Comment(0)
S
0

In my case, MongoDB windows service has been stopped. just check whether the service is in Running status

enter image description here

Hope this helps

Southsouthwest answered 6/12, 2023 at 9:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.