我一直在寻找几个小时,而且我无法找到为什么这不起作用,你能帮我个忙吗?我试图在我的项目上实现mongodb,似乎连接正常,但当我尝试修改/访问它时,它给了我这个" Mongo Timeout Exception"。
try {
MongoCredential credential = MongoCredential.createCredential(USER, DATABASE, PASSWORD.toCharArray());
MongoClient mongoClient = new MongoClient(new ServerAddress(HOST), Arrays.asList(credential));
DB database = mongoClient.getDB(DATABASE);
DBCollection collection = database.getCollection(COLLECTION);
DBCursor cursor = collection.find();
cursor.next();
System.out.println("Success!");
} catch(Exception ex) { ex.printStackTrace(); }
com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=104.236.68.242:27017, type=Unknown, state=Connecting}]
at com.mongodb.BaseCluster.getDescription(BaseCluster.java:128)
at com.mongodb.DBTCPConnector.getClusterDescription(DBTCPConnector.java:394)
at com.mongodb.DBTCPConnector.getType(DBTCPConnector.java:571)
at com.mongodb.DBTCPConnector.isMongosConnection(DBTCPConnector.java:368)
at com.mongodb.Mongo.isMongosConnection(Mongo.java:622)
at com.mongodb.DBCursor._check(DBCursor.java:494)
at com.mongodb.DBCursor._next(DBCursor.java:551)
at com.mongodb.DBCursor.next(DBCursor.java:701)
at net.Heiden.DB.Testing.main(Testing.java:29)
任何帮助都是相关的。 谢谢^^