'Connection Error in Mongo DB in Windows

I am super new in doing MongoDB. Today is my first time doing it. The MongoDB is setup by someone else before that so I need some help here.

I tried starting mongo and this is the error:

C:\MongoDB>mongo
MongoDB shell version: 3.2.12
connecting to: test
2017-05-05T17:36:18.459+0800 W NETWORK  [thread1] Failed to connect to 
127.0.0.1
:27017 after 5000ms milliseconds, giving up.
2017-05-05T17:36:18.459+0800 E QUERY    [thread1] Error: couldn't connect to 
server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14@(connect):1:6

exception: connect failed

I also tried starting mongod.exe and there is error. Not sure if it's interlink or not.

C:\MongoDB>mongod.exe
2017-05-05T17:52:42.543+0800 I CONTROL  [initandlisten] MongoDB starting : 
pid=2
1708 port=27017 dbpath=C:\data\db\ 64-bit host=xxxx
2017-05-05T17:52:42.544+0800 I CONTROL  [initandlisten] targetMinOS: Windows 
7/Windows Server 2008 R2
2017-05-05T17:52:42.545+0800 I CONTROL  [initandlisten] db version v3.2.12
2017-05-05T17:52:42.545+0800 I CONTROL  [initandlisten] git version: 
ef3e1bc78e997f0d9f22f45aeb1d8e3b6ac14a14
2017-05-05T17:52:42.545+0800 I CONTROL  [initandlisten] OpenSSL version: 
OpenSSL1.0.1u-fips  22 Sep 2016
2017-05-05T17:52:42.546+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2017-05-05T17:52:42.546+0800 I CONTROL  [initandlisten] modules: none
2017-05-05T17:52:42.546+0800 I CONTROL  [initandlisten] build environment:
2017-05-05T17:52:42.546+0800 I CONTROL  [initandlisten]     distmod: 
2008plus-ssl
2017-05-05T17:52:42.547+0800 I CONTROL  [initandlisten]     distarch: x86_64
2017-05-05T17:52:42.547+0800 I CONTROL  [initandlisten]     target_arch: 
x86_64
2017-05-05T17:52:42.547+0800 I CONTROL  [initandlisten] options: {}
2017-05-05T17:52:42.548+0800 I STORAGE  [initandlisten] exception in 
initAndListen: 29 Data directory C:\data\db\ not found., terminating
2017-05-05T17:52:42.548+0800 I CONTROL  [initandlisten] dbexit:  rc: 100

I did see that data\db is created but just not in C:\ .In the config file, there is already a path written.

systemLog:
path: D:\MongoDB\mongod.log
storage:
dbPath: D:\mongod\data\db


Solution 1:[1]

By default, mongod will attempt to use \data\db on the drive which you start MongoDB as its dbpath. In your case, that's C:\data\db.

If you'd like to start mongod as configured by the previous person (including access to its data), you need to provide option --config to mongod to point to the configuration file. This will set mongod to use the config file and run according to the setup provided (as configured by the previous person). i.e. using D:\data\db.

See also: Run MongoDB Community Edition (Windows) and mongo shell

Solution 2:[2]

After add inbound rule for tcp 27017 port at firewall you should add the external IP Adress into config file, [mongod.cfg]

        # network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1, add external ip here

Solution 3:[3]

I had that problem too. In my case, I start mongodb server first Here what i did

  • open cmd as administrative
  • type net start MongoDB
  • then type mongo

Hope this will solve your problem

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wan Bachtiar
Solution 2 Mucahid Uslu
Solution 3 Assy