无法在提供的主机和端口上连接到 MongoDB

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42739166/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:55:30  来源:igfitidea点击:

Could not connect to MongoDB on the provided host and port

mongodbmongodb-compass

提问by Ege Kuzubasioglu

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:

我只想尝试 MongoDB Compass GUI for MongoDB,但是当我尝试使用本地主机端口连接时:27017 我收到此错误:

Could not connect to MongoDB on the provided host and port

无法在提供的主机和端口上连接到 MongoDB

I followed theseinstructions on YouTube.

我在 YouTube 上遵循了这些说明。

回答by Sibeesh Venu

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 MongoDBservice has been started in services.msc.

我今天遇到了这个问题,后来我发现这是一个设置问题。如果您在首次设置 MongoDB 时也遇到此问题,以下步骤可能会对您有所帮助。确保MongoDB服务已在services.msc.

  1. Go to C drive and create a folder dbin the path C:\data\db, if you don't see datafolder in C drive, please create it first and then dbfolder 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.
  1. 转到C盘并db在路径中创建一个文件夹C:\data\db,如果您data在C盘中没有看到文件夹,请先创建它,然后db在评论中提到@sebastian文件夹。
  2. 转到您安装 MongoDB 的文件夹,就我而言,它是 C:\Program Files\MongoDB\Server\3.6\bin
  3. 输入命令 C:\Program Files\MongoDB\Server\3.6\bin>mongod
  4. 这将在您的机器上设置 MongoDB,您将获得如前所述的输出。

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

C:\Program Files\MongoDB\Server\3.6\bin>mongod 2018-03-11T07:02:56.558-0700 I CONTROL [initandlisten] MongoDB 开始: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.
  1. 现在,如果您尝试连接,您可能不会遇到问题。

enter image description here

在此处输入图片说明

回答by BloodLoss

Press windows key button and search Servicesand find MongoDBthen start. Then try again. It will work

按windows键按钮并搜索服务并找到MongoDB然后启动。然后再试一次。它会工作

回答by Bastion

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

  • 编辑 /etc/mongod.conf
  • 在网络下,通过在行的开头放置 # 来注释以下内容:

    绑定IP:127.0.0.1

-- What went wrong: --

- 什么地方出了错: -

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

原因:bindIp 导致它拒绝外部请求,因此我们需要删除该设置。

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).

我的 mongo 是 Red Hat (RHEL6) 的标准 yum 安装,这是默认配置的方式(我从 mongoDB 2.6 开始并逐步升级到 3.4)。

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

编辑:对于 MongoDB 2.4 及更早版本使用:bind_ip = 127.0.0.1

回答by Manohar Reddy Poreddy

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

挣扎了3个小时。
以下是 3 个步骤的完整过程:



On MongoDB server machine

在 MongoDB 服务器机器上

Get the IP adresss:

获取 IP 地址:

  1. run CMDor Command prompt
  2. run ipconfigcommand
    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
  1. 运行CMD或命令提示符
  2. 运行ipconfig命令
    查找类似于
    IPv4 地址下方的行。. . . . . . . . . . :10.111.11.111
  3. 复制上面的IP值,也就是10.111.11.111,你可以不一样

Edit the bindIP in MongoDB Server config file:

编辑 MongoDB 服务器配置文件中的 bindIP:

  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
  1. 打开 C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg
    查找以下行:
    bindIp: 127.0.0.1
  2. 在末尾添加一个逗号,并粘贴复制的 IP,如下所示:
    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 hostnamein cmdto get the name of your computer)

注意:如果您的IP地址改变日常的话,最好是编写计算机名称(类型hostnamecmd得到您的计算机的名称)

Restart the MongoDB Server

重启MongoDB服务器

  1. run the services.msccommand
    scroll down on the right to select MongoDB Server
    on the left-top, Restart the service
  1. 运行services.msc命令
    在右侧向下滚动以选择MongoDB Server
    左上角,Restart the service


On Client machine

在客户端机器上

Connect to MongoDb server, from another machine

从另一台机器连接到 MongoDb 服务器

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

现在,您可以从另一台机器连接。使用客户端,例如MongoDB Compass或其他:

  1. Connection is possible using it's IP 10.111.11.111, give it in Hostnamein MongoDB Compass client
  2. Hostnamein MongoDB Compass client can also be the server's computer name like W11ABC11A11. To get computer name of your MongoDB server, use hostnamein CMD(on the MongoDB server computer).
  1. 可以使用它的 IP 进行连接10.111.11.111Hostname在 MongoDB Compass 客户端中 提供它
  2. Hostname在 MongoDB Compass 客户端也可以是服务器的计算机名称,如 W11ABC11A11。要获取 MongoDB 服务器的计算机名称,请使用hostnamein CMD(在 MongoDB 服务器计算机上)。


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

完成上述所有操作后,如果您遇到问题,则:
- 使用 ping 对方(来自服务器的客户端,反之亦然)使用ipconfig,使用命令ping IPhere,您应该得到Reply from ..不应该得到的Request timed out.
- 如果您在上面看到问题:
- 重新启动客户端机器, 再次 ping
-- 如果仍有问题,请让 DB 所有者重新启动服务器机器一次(如果是开发服务器,空闲时重新启动应该没有任何问题。)
-- 问题仍然存在?验证以上所有步骤

Hope that helps.

希望有帮助。

回答by Rafa? Bochniewicz

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
  1. 尝试启用 cmd 输入命令 -> mongod
  2. 然后尝试使用 MongoDb Compass 程序连接你必须一直有一个打开的控制台

回答by Likwidsage

edit /etc/mongod.conf

编辑 /etc/mongod.conf

Under the net settings

在网络设置下

bindIp: 0.0.0.0

回答by Supriyo Das

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

如果您在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.

打开您的任务管理器并转到“服务”选项卡。检查 MongoDB 服务器是否已停止。如果停止,请右键单击它并启动服务器。然后再试一次。问题将得到解决。

回答by Hanzla Habib

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

如果您在 Windows 上工作,这是一个常见问题。

Creating data/dbfolder on cdrive and then running mongod from C:\Program Files\MongoDB\Server\4.2\binand then connecting from mongodb compass resolves my issue

data/dbc驱动器上创建文件夹C:\Program Files\MongoDB\Server\4.2\bin,然后从 mongodb compass运行 mongod然后从 mongodb compass 连接解决了我的问题

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

基本上在 c 驱动器上,你应该有一个data文件夹,其中包含db我所理解的文件夹,我只是分享了某人可能会从中得到帮助:)

回答by user7849113

  • please start mongoDB before use Compass GUI
  • 请在使用 Compass GUI 之前启动 mongoDB

回答by Uzzal Basak

My MongoDBInstalled machine firewall was enabled that's why I can not from Remote machine MongoDBcompass

我的MongoDBInstalled 机器防火墙已启用,这就是为什么我不能从远程机器MongoDB指南针

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

禁用防火墙后,我可以从远程 MongoDB指南针进行连接。

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

Thanks

谢谢