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:26

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.

查看更多
劳资没心,怎么记你
3楼-- · 2020-02-09 07:26

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

查看更多
时光不老,我们不散
4楼-- · 2020-02-09 07:26

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?

查看更多
登录 后发表回答