Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not connect to MongoDB on the provided host and port

I just want to try MongoDB Compass GUI for MongoDB, but when I try to connect using local host port: 27017 I get this error:

Could not connect to MongoDB on the provided host and port

I followed these instructions on YouTube.

like image 746
Ege Kuzubasioglu Avatar asked Mar 11 '17 18:03

Ege Kuzubasioglu


People also ask

How do I find my MongoDB host and port?

By default, MongoDB starts at port 27017. But you can access it in a web browser not at that port, rather, at a port number 1000 more than the port at which MongoDB is started. So if you point your browser to http://localhost:28017, you can see MongoDB web interface.

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.

Could not connect to MongoDB on the provided host and port in Ubuntu?

It looks like you are trying to access MongoDB over HTTP on the native driver port. If you are still not able to connect, please check if this port is getting used by any other application. Make the port 27017 free and restart Compass and try logging in again.


2 Answers

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

like image 57
Sibeesh Venu Avatar answered Oct 03 '22 03:10

Sibeesh Venu


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

like image 27
BIS Tech Avatar answered Oct 03 '22 05:10

BIS Tech