Could not connect to MongoDB on the provided host and port
Asked Answered
F

15

50

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.

Fairlead answered 11/3, 2017 at 18:46 Comment(0)
T
53

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

Tearjerker answered 11/3, 2018 at 14:13 Comment(7)
this works, I was also facing the issue and I installed first time.Neufer
can I create the db folder in the path other than C:\data\db?Antons
this answer worked out for my problem but there are different things may cause this, so I'm not accepting this answer to not mislead peopleFairlead
@EgeKuzubasioglu I do agree, but leaving a question unaccepted will result in, this question be available in unanswered/unaccepted category.Tearjerker
Thanks, Sibeesh Venu All I did is created C:\data\db path and run mongod using cmd, after mongo with another cmd and it worked :)Hegemony
thanks i did all of this but i had to create the C:\data folder and then the db folder and just simply typed mongod into the command lineNita
@Nita Thanks, I will add this to the answer.Tearjerker
Q
36

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

Quittance answered 6/3, 2018 at 1:40 Comment(3)
Thanks a lot, this did the trick for me ... i knew it was a mater of a simple restart, cause every thing worked fine before and i didn't made any change on my configAriannearianrhod
Super. Why did this came to my mind earlier... Thanks a lotSecretory
Worked well --- It's strange that this works, but dosen't work when restarting from cmd promt...Jopa
M
19

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

Maratha answered 24/8, 2017 at 2:8 Comment(3)
Could you please share steps for windows server?Woodshed
this is the correct answer. the spelling is bind_ip = 127.0.0.1 in my server though.Gaige
Or you can use 127.0.0.1 instead of localhost for connection.Morello
A
14

Struggled for 3 hours.
Here is full procedure in 3 steps:


On MongoDB server machine

Get the IP adresss:

  1. run CMD or Command prompt
  2. run ipconfig command
    Look for a line that is like below
    IPv4 Address. . . . . . . . . . . : 10.111.11.111
  3. Copy above IP value, which is 10.111.11.111, it can be different for you

Edit the bindIP in MongoDB Server config file:

  1. Open C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg
    Look for the below line:
    bindIp: 127.0.0.1
  2. Add a COMMA at the end, and paste the copied IP, like below:
    bindIp: 127.0.0.1,10.111.11.111

NOTE: If your IP address changes everyday, then best is to write the computer name (type hostname in cmd to get the name of your computer)

Restart the MongoDB Server

  1. run the services.msc command
    scroll down on the right to select MongoDB Server
    on the left-top, Restart the service

On Client machine

Connect to MongoDb server, from another machine

Now, you can connect from another machine. Use a client, like MongoDB Compass or other:

  1. Connection is possible using it's IP 10.111.11.111, give it in Hostname in MongoDB Compass client
  2. Hostname in MongoDB Compass client can also be the server's computer name like W11ABC11A11. To get computer name of your MongoDB server, use hostname in CMD(on the MongoDB server computer).

Troubleshooting/ issues?

After doing all above, if you have issues, then:
- ping each other (client from server, and vice versa) using ipconfig, using command ping IPhere , you should get Reply from .. should not get Request timed out.
- if you see issues in above:
-- Restart the client machine, ping again
-- If you still have issues, have DB owner to restart the server machine once (if it is dev server there should not be any problem to restart when its idle.)
-- issues still? verify all above steps

Hope that helps.

Ashcan answered 7/8, 2018 at 3:35 Comment(2)
This is the only thing that worked for me. Thank you!Clarence
For me, comma separating with 0.0.0.0 worked (instead of entirely replacing the existing IP). So I have bindIp: 127.0.0.1,0.0.0.0. Hoping this means I don't need to change the IP if the host IP is dynamic.Clarence
M
9

I had the same problem

  1. try to enable cmd enter the command -> mongod
  2. then try to connect using the MongoDb Compass program You must have an open console all the time
Mendy answered 4/2, 2018 at 20:29 Comment(0)
S
5

edit /etc/mongod.conf

Under the net settings

bindIp: 0.0.0.0
Sweeper answered 23/5, 2019 at 12:49 Comment(1)
Change the bindIp works for me. I also disable the firewalld service.Loesch
A
4

It's a common problem if you are working on Windows.

Open your task manager and go to the Services tab. Check if the MongoDB server is stopped or not. If stopped, right click on it and start the server. Then try again. The problem will be solved.

Angara answered 24/6, 2019 at 17:7 Comment(1)
OP didn't specify that they were working in a Windows environment. Not all operating systems have a Task Manager.Manus
C
1

Wasted a lot of time on this, seemingly tried it all and literally none of these solutions worked for me...

Ultimately, my MongoDb seems to want to ignore my config file, since commenting out the bind_ip field should do the same thing.

Try starting mongo like this

mongod --bind_ip_all

Alternatively, you can specify specific IPs

mongod --bind_ip <IP>
Contraception answered 15/2, 2019 at 18:18 Comment(0)
N
0
  • please start mongoDB before use Compass GUI
Nimitz answered 19/3, 2018 at 7:39 Comment(0)
G
0

My MongoDB Installed machine firewall was enabled that's why I can not from Remote machine MongoDB compass

After disabled the firewall, I am able to connect from Remote MongoDB compass.

[17:32:51 oracle@test2 bin]$ service firewalld stop

Thanks

Grassquit answered 30/10, 2018 at 8:39 Comment(0)
B
0

Check if 27017 port is enabled / Opened in your .conf file .. This is because 27017 port is not opened as default and also you need to add your IP in the TCP IN to make your internet IP connect remotely..

Braden answered 31/10, 2018 at 9:38 Comment(0)
P
0

It's a common problem if you are working on Windows.

Creating data/db folder on c drive and then running mongod from C:\Program Files\MongoDB\Server\4.2\bin and then connecting from mongodb compass resolves my issue

basicly on c drive you should have data folder which holds db folder that's what i understood by this i just shared someone might get help from this :)

Protean answered 25/12, 2019 at 19:43 Comment(0)
S
0

I was having similar problem while using MongoDB on EC2 instance and was trying to connect to it through Mongodb compass.

On Mongodb Compass authentication screen, changing the port to 443 worked because my mongod service was listening on 443. enter image description here

Shaver answered 1/1, 2021 at 11:44 Comment(0)
B
0

I am on Ubuntu and I simply did it by checking the 'mongod.conf' file. Make sure that following parameters are set:

net:
  port: 27017
  bindIp: 127.0.0.1

And after every change I suggest you go with

sudo systemctl restart mongod.service

Bioluminescence answered 4/1, 2021 at 8:33 Comment(0)
W
0

By default IPv6 disabled and this may be a reason of the failed connection by Hostname. Try to add IPv6 support:

# network interfaces
net:
  ipv6: true
  port: 27017
  bindIp: 127.0.0.1, MyDomain.com
Winifredwinikka answered 5/11, 2022 at 10:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.