MongoDb connection refused

2020-02-09 06:24发布

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!

9条回答
来,给爷笑一个
2楼-- · 2020-02-09 07:03

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.

查看更多
何必那么认真
3楼-- · 2020-02-09 07:10

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.

查看更多
爷、活的狠高调
4楼-- · 2020-02-09 07:13

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
查看更多
霸刀☆藐视天下
5楼-- · 2020-02-09 07:20

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.

查看更多
Ridiculous、
6楼-- · 2020-02-09 07:23

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

查看更多
走好不送
7楼-- · 2020-02-09 07:25

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.

查看更多
登录 后发表回答