MongoDb 连接被拒绝

发布于 2024-11-17 13:27:26 字数 931 浏览 4 评论 0原文

这是我第一次尝试使用 MongoDB。我已经让 Mongo 运行:

ps -ef | grep [m]ongo
mongodb  11023  1  0 Jun24 ? 00:00:03 /usr/lib/mongodb/mongod --config /etc/mongodb.conf

并且错误是由于执行

Datastore.save( stuff );  // (pseudo code)

错误而出现的:

2011 年 6 月 27 日下午 3:20:29 com.mongodb.DBTCPConnector fetchMaxBsonObjectSize
警告:使用 0 确定 maxBSON 大小时出现异常
java.io.IOException:无法连接到 [russ-elite-book/127.0.1.1:27017] bc:java.net.ConnectException:连接被拒绝
    在 com.mongodb.DBPort._open(DBPort.java:206)
    在 com.mongodb.DBPort.go(DBPort.java:94)
    在 com.mongodb.DBPort.go(DBPort.java:75)
    在 com.mongodb.DBPort.findOne(DBPort.java:129)
    在 com.mongodb.DBPort.runCommand(DBPort.java:138)
    ...

请注意,我使用 127.0.0.1:27017 进行连接,该连接适用于 Mongo shell。另外,我使用 http://localhost:28017 在浏览器中获取管理页面。

非常感谢您的任何和所有想法!

This is my first attempt to consume MongoDB. I've got Mongo running:

ps -ef | grep [m]ongo
mongodb  11023  1  0 Jun24 ? 00:00:03 /usr/lib/mongodb/mongod --config /etc/mongodb.conf

And the error comes as the result of doing

Datastore.save( stuff );  // (pseudo code)

The error:

Jun 27, 2011 3:20:29 PM com.mongodb.DBTCPConnector fetchMaxBsonObjectSize
WARNING: Exception determining maxBSON size using0
java.io.IOException: couldn't connect to [russ-elite-book/127.0.1.1:27017] bc:java.net.ConnectException: Connection refused
    at com.mongodb.DBPort._open(DBPort.java:206)
    at com.mongodb.DBPort.go(DBPort.java:94)
    at com.mongodb.DBPort.go(DBPort.java:75)
    at com.mongodb.DBPort.findOne(DBPort.java:129)
    at com.mongodb.DBPort.runCommand(DBPort.java:138)
    ...

Note that I'm using 127.0.0.1:27017 for my connection, which works to the Mongo shell. Also, I get the admin page in the browser using http://localhost:28017.

Profuse thanks for any and all ideas!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

呆° 2024-11-24 13:27:26

我遇到了同样的问题,因为我使用brew升级了我的mongo。为了解决这个问题。查找conf文件(可能不在启动mongodb的bin目录中)

/usr/local/Cellar/mongodb-2.2.whatever/mongod.conf,并注释掉“bind_ip”属性。

I ran into the same issue because I upgraded my mongo using brew. To fix this issue. Look for the conf file(which might not be located in the bin directory where you start your mongodb from)

/usr/local/Cellar/mongodb-2.2.whatever/mongod.conf, and comment out the "bind_ip" property.

旧时模样 2024-11-24 13:27:26

(我认为回答自己的问题有点不好,但事实上,答案并不是这些建议的答案。尽管如此,我还是非常感谢他们所有人。在回答问题时,人们需要能够假设它基于正确安装和工作的软件。我没有这个。)

我使用 Ubuntu 软件中心安装了 MongoDB。正如本问题其他地方所述,它从外壳和浏览器运行。然而,它在 Java 中不起作用(在 Django 中也不起作用)。

尽管 Java 堆栈跟踪中显示了该问题,但该问题只是“连接被拒绝”。

解决方案是从正确的 Mongo 源安装它,而不是信任 Ubuntu 存储库。

(是的,从那里获得的其他产品也经常发生这种情况,例如 Eclipse,但你知道它是如此的好您想要信任它的服务。)

如果您想了解我如何安装然后起作用的内容,请查看http://www.javahotchocolate.com/tutorials/mongodb.html

(I think it slightly bad form to answer one's own question, but in fact, the answer turns out to be none of those suggested. Nevertheless, my profuse thanks to all of them. When answering a question, one needs to be able to assume it's based on correctly installed and working software. I did not have that.)

I installed MongoDB using the Ubuntu Software Center. It worked from the shell and from the browser as noted elsewhere in this question. However, it did not work from Java (nor from Django either).

The problem, despite what it said in the Java stack trace, was simply "connection refused."

The solution is to install it from proper Mongo sources and not to trust the Ubuntu repository.

(Yes, this also frequently happens to other products obtain from there too, like Eclipse, but you know it's such a nice service that you want to trust it.)

If you want to read how I installed what then worked, check out http://www.javahotchocolate.com/tutorials/mongodb.html.

两个我 2024-11-24 13:27:26

我有同样的问题,但我的解决方案不同。我使用“localhost”作为主机名并将其更改为“127.0.0.1”修复了它。

I had the same problem, but my solution was different. I was using "localhost" as the host name and changing it to "127.0.0.1" fixed it.

勿忘初心 2024-11-24 13:27:26

Java 驱动程序很可能无法连接到指定的地址。
确保您可以使用 shell 连接到该地址 127.0.1.1:27017 并运行“db.isMaster()”。
也许这是 127.0.1.1127.0.0.1 的问题。

Most likely the Java driver cannot connect to the address specified.
Make sure that you can connect to that address 127.0.1.1:27017 using the shell and run "db.isMaster()".
Maybe it is an issue of 127.0.1.1 vs 127.0.0.1.

最单纯的乌龟 2024-11-24 13:27:26

事实证明,这是Java MongDB 驱动程序的问题

有两种解决方案:

  1. 使用 2.8 版 或更高版本的 Java 驱动程序。
  2. 编辑配置文件,如果它包含行 bind_ip = 127.0.0.1bind_ip = localhost,请将其注释掉。

吃简陋的馅饼...

正如我在 Russ Bateman 自己的回答的评论中所示,这似乎是 Ubuntu 的问题首先打包。真正的原因是它附带的配置文件确实为 bind_ip 定义了一个值...

It turns out that it is an issue with the Java MongDB driver.

There are two solutions:

  1. Using version 2.8 or higher of the Java driver.
  2. Edit the configuration files and if it contains the line bind_ip = 127.0.0.1 or bind_ip = localhost, comment it out.

Eating humble pie...

As I showed in my comment to Russ Bateman's own answer, it seemed like an issue with the Ubuntu package at first. The real reason is that the config file that comes with it does define a value for bind_ip...

半步萧音过轻尘 2024-11-24 13:27:26

我遇到了同样的问题,因为我使用 apt-get 安装了 mongo。修复方法如下:

  1. 找到您的 mongod.conf 文件。在 Ubuntu 14.04 中,它是 /etc/mongod.conf
  2. 打开 mongod.conf 文件并输入命令 bindIp = 127.0.0.1
  3. 重新启动 mongod

I ran into the same issue because I installed my mongo using apt-get. Here's how to fix it:

  1. Find your mongod.conf file. In Ubuntu 14.04, it's /etc/mongod.conf
  2. Open mongod.conf file and command the line bindIp = 127.0.0.1
  3. Restart mongod
梦在深巷 2024-11-24 13:27:26

这似乎是一个安全问题或无效的网址。如果您使用默认配置,您应该能够访问 http://yourmachine:28017。看看您是否可以从此网址导航到管理页面。如果您能够导航到管理 URL,只需在应用程序中将端口号替换为 27017 即可。它应该有效。

It appears that this is a security issue or an invalid url. If you used the default configuration, you should be able to access the http://yourmachine:28017. See if you can navigate to the admin page from this url. If you are able to navigate to the admin url, just replace the port number with 27017 in your app. It should work.

可爱暴击 2024-11-24 13:27:26

如果没有看到 .conf 文件内容,很难说。我建议的一件事是运行 mongo shell 并查看是否可以通过它进行连接、查询和写入。这将有助于隔离服务器与 Java 客户端问题。此外,它可能会为您提供不同形式的错误,这可能是一个提示。

您是否在 .conf 文件中设置 --port ?

It's hard to say without seeing your .conf file contents. One thing I would recommend is running the mongo shell and seeing if you can connect, query, and write from it. This will help isolate server vs. a java client issue. Additionally it may give you a different form of the error which may be a hint.

Are you setting --port in your .conf file?

断爱 2024-11-24 13:27:26

对我来说,这是一个完全不同的解决方案。我正在使用 Spring MVC 框架,我所要做的就是确认配置 XML 文件在 /target 文件夹以及非目标文件夹中表示相同的内容。一旦调整好,一切就正常了。问题是从 STS 运行时一切正常,但部署时出现上述错误。

For me, it was a completely different solution. I am using Spring MVC framework, and all I had to do is to confirm that the configuration XML files are saying the same thing in the /target folder as well as the non-target folders. Once that was adjusted, everything worked. The problem was that everything worked when run from a STS, but when deployed, I had the mentioned error.

百善笑为先 2024-11-24 13:27:26

就我而言,我使用 pymongo 连接到 mongo atlas 集群。有一个连接限制,我怀疑我打开了太多连接,因此重写代码以共享一个连接并正确关闭它解决了问题。

In my case I was using pymongo connecting to mongo atlas cluster. There is a connection limit and I suspected I opened too many connections so rewriting the code to share one connection and properly closing it solved the problem.

故事与诗 2024-11-24 13:27:26

如果您是 Windows 用户,您的 mongdb 将显示连接拒绝错误,如果您在本地主机上,您的 mongdb 可能不会在后台运行。因此,转到服务并打开 mogodb。

If you are a Windows user,your mongdb shows an error of connection refusal, and if you are on localhost, your mongdb might not be running in the background. So,go to service and turn mogodb on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文