mongodb java 拒绝连接,MongoDb连接被拒绝

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!

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值