MongoDb connection refused

大憨熊 提交于 2019-11-29 01:19:40

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.

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

agirbal

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.

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.

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
Rodrigue

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

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.

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?

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!