MongoDB on a Windows 7 machine: connection cannot be made

After I started using Mongo using mongod.exe on a computer running Windows 7, I tried to start the mongo shell with an 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: could not connect to server 127.0.0.1:27017 (127.0.0.1), the connection attempt was unsuccessful when calling src / mongo / shell / mongo.js: 146: connection failed

In CMD, where I run mongod, the output is:

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

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 information: 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] restore: no log files are present, no recovery is required

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

Any suggestion to fix this problem?

+29
initialization mongodb
May 18 '14 at 20:45
source share
9 answers

What I decided to solve was to create a startmongo.conf file that sets bind_ip to 127.0.0.1. After that, I just created * .bat to start mongo using something like:

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

Details may appear in this message .

+10
May 24 '14 at 5:31
source share

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 .

+31
05 Oct '14 at 16:14
source share

I am having this problem. What is the fixed mine:

  • Suppose you have a directory: "C:\mongo_databse"
  • Open a command prompt and type (suppose you add the Mongo bin directory to PATH): mongod --dbpath=C:/mongo_database . There will be several logs on the command line.

  • Now open the command line OTHER , then enter mongo , then it will work.

+18
Feb 06 '15 at 7:27
source share
  • I assume that your mongo.config file will be inside the mongodb folder at the same level in the bin directory. The contents of the mongo.config file:

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

    do not forget to create a data folder and a log folder at the same level of the bin directory inside the log folder, create an empty mongo.log file.

  • Point your command line to C: \ mongodb \ bin where the bin mongo db folder is located.

  • create mongo db service when entering text

     mongod.exe --storageEngine=mmapv1 --config=../mongo.config 
  • Now you can start the mongo db service as

     net start mongodb 
  • Finally, you can connect to the mongo db server from printing the mongo db client

     mongo.exe 
  • As soon as you successfully go from step 1 to step 3 from the next time to the wards, you only need steps 4 and 5. to start the service and connect.

+6
Dec 17 '15 at 9:59
source share

I got this error due to lack of disk space. Check out your mongo magazine.

+2
Jul 19 '14 at 19:23
source share

I had a similar error when I tried to run my mongo db through cmd. However, the difference was that I had a configuration file that had a path to the db and log folders and wanted to use them. I used mongo a few days ago and it worked fine, but when I started using it again today, it gave me an 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 is how I fixed it:

  • Open cmd as admin and go to the bin folder of your MongoDB and type: mongod --config <path to your config file> --install
  • Now start the mongo db service: net start mongodb you should receive a message saying: The MongoDB service was started successfully.
  • close this command line and open another as administrator, go to the bin folder again and enter mongo

This will lead you to the mongodb test .

Press ctrl + c at any time to exit.

Hope this helps.

+1
May 27 '15 at 14:50
source share

I had a very similar experience on @ user1501382, but slightly changed everything according to the documentation

1) cd c: // changes to drive C

2) mkdir data // creates directory data

3) cd data

4) mkdir db // creates the db directory

5) cd db // changes the 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
Feb 18 '15 at 20:29
source share

for mongodb 3.0 versions use "--smallfiles".

eg: -

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

0
Oct 24 '15 at 17:37
source share

I am not sure if there is a better way to run this. For me, I use these settings to create a directory and define a new path for MongoDB. The important thing for me is that I do not start it as a server ( mongod ), and after that I mongo to another terminal, which gives me the opportunity to use the database. I hope this can help someone.

0
May 24 '19 at 5:54
source share



All Articles