Could not connect to MongoDB on the provided host and port

I had faced this issue today and later I found that it was a set up problem. If you are also facing this issue while you set up MongoDB for the first time, following steps may help you. Make sure that MongoDB service has been started in services.msc.

  1. Go to C drive and create a folder db in the path C:\data\db, if you don't see data folder in C drive, please create it first and then db folder as @sebastian mentioned in the comment.
  2. Go the folder, where you had installed MongoDB, in my case, it was C:\Program Files\MongoDB\Server\3.6\bin
  3. Type the command C:\Program Files\MongoDB\Server\3.6\bin>mongod
  4. This will set up the MongoDB on your machine, and you will get an output as preceding.

C:\Program Files\MongoDB\Server\3.6\bin>mongod 2018-03-11T07:02:56.558-0700 I CONTROL [initandlisten] MongoDB starting : pid=18720 port=27017 dbpath=C:\data\db\ 64-bit host=SibeeshVenu 2018-03-11T07:02:56.558-0700 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2

  1. Now if you try connecting, you may not be getting the issue.

enter image description here


Press windows key button and search Services and find MongoDB then start. Then try again. It will work


In case other people have this error, here is what worked for me:

  • Edit /etc/mongod.conf
  • Under network comment out the following by placing a # at the beginning of the line:

    bindIp: 127.0.0.1

-- What went wrong: --

Reason: bindIp was causing it to reject external requests, so we need to remove that setting.

My mongo was the standard yum install for Red Hat (RHEL6) and this is how it was configured by default (I had started with mongoDB 2.6 and upgraded in steps to 3.4).

EDIT: For MongoDB 2.4 and earlier use: bind_ip = 127.0.0.1