0

I have an issue with MongoDB version 2.0.1. I have installed it on an Ubuntu machine that is 32 bit. I am able to connect to it through the command prompt, but not able to connect to it through Java code. This same code used to work with the older MongoDB version. I get the following exception.

    Caused by: com.mongodb.MongoInternalException: DBPort.findOne failed
       at com.mongodb.DBPort.findOne(DBPort.java:153)
       at com.mongodb.DBPort.runCommand(DBPort.java:159)
       at com.mongodb.DBTCPConnector.testMaster(DBTCPConnector.java:369)
       at com.mongodb.Mongo.<init>(Mongo.java:140)
       at
com..bean.MongoCollectionPoolBean.init(MongoCollectionPoolBean.java:
42)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
57)
       at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
43)
       at java.lang.reflect.Method.invoke(Method.java:616)
       at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:
1544)
       at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:
1485)
       at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:
1417)
       ... 24 more
        Caused by: java.io.IOException: couldn't connect to
    [domU-12-31-39-0B-26-01/67.265.65.132:27017]
    bc:java.net.ConnectException: Connection timed out
           at com.mongodb.DBPort._open(DBPort.java:205)
           at com.mongodb.DBPort.go(DBPort.java:85)
           at com.mongodb.DBPort.findOne(DBPort.java:145)
           ... 35 more

When I try to reproduce the same problem with my local system (Mac Lion 64 bit) it works fine. When I see the server logs here is what i see on my local system:

[clientcursormon] mem (MB) res:14 virt:2434 mapped:0

and on Ubuntu (where it is not working)

[clientcursormon] mem (MB) res:14 virt:86 mapped:0

4

1 回答 1

0

如果您的应用程序在同一个盒子上连接到 mongodb,则使用 127.0.0.1 以便在您的亚马逊实例更改 IP 地址时它不会中断。一般来说,最好使用通过 /etc/hosts 或 dns 指向 IP 的主机名。如果这仍然不起作用,请确保您可以从本地终端执行“telnet localhost 27017”。如果无法连接,则说明 mongodb 未在该端口上运行,或者您有防火墙。

于 2011-12-06T00:20:39.630 回答