Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 818
ucaiado Avatar asked May 18 '14 20:05

ucaiado


People also ask

Why is my MongoDB not connecting?

Ensure that your MongoDB instance is running: Compass must connect to a running MongoDB instance. Also check you have installed MongoDB and have a running mongod process. You should also check that the port where MongoDB is running matches the port you provide in the compass connect.

How do you fix no connection could be made because the target machine actively refused it MongoDB?

Here's how I fixed it : Open cmd as admin and navigate to the bin folder of your MongoDB and type : mongod --config <path to your config file> --install. Now start your mongo db service : net start mongodb you should get a message which says : The MongoDB service was started successfully.


1 Answers

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.

like image 95
user1501382 Avatar answered Sep 22 '22 11:09

user1501382