简体   繁体   English

MongoTimeoutException 与 Java。 在收到问题之前没有任何更改

[英]MongoTimeoutException with Java. No changes before getting the issue

I m facing with this issue:我正面临这个问题:

com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.Mongo$4@11ad6cd. Client view of cluster state is {type=REPLICA_SET, servers=[{address=bastaproject-shard-00-01-vo5a5.gcp.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}, {address=bastaproject-shard-00-00-vo5a5.gcp.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}, {address=bastaproject-shard-00-02-vo5a5.gcp.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}]
    at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:389)
    at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:108)
    at com.mongodb.Mongo.getConnectedClusterDescription(Mongo.java:887)
    at com.mongodb.Mongo.createClientSession(Mongo.java:877)
    at com.mongodb.Mongo$3.getClientSession(Mongo.java:866)
    at com.mongodb.Mongo$3.execute(Mongo.java:823)
    at com.mongodb.MongoCollectionImpl.executeCount(MongoCollectionImpl.java:215)
    at com.mongodb.MongoCollectionImpl.count(MongoCollectionImpl.java:183)
    at com.mongodb.MongoCollectionImpl.count(MongoCollectionImpl.java:178)
    at basta.telegram.MongoDAO.subscribed(MongoDAO.java:31)
    at basta.telegram.BastaBot.onUpdateReceived(BastaBot.java:55)
    at java.util.ArrayList.forEach(ArrayList.java:1249)
    at org.telegram.telegrambots.generics.LongPollingBot.onUpdatesReceived(LongPollingBot.java:27)
    at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$HandlerThread.run(DefaultBotSession.java:309)

I was able to connect with the database and get document's but now i cant.我能够连接数据库并获取文档,但现在我不能。 I did'nt change nothing at all in the code before getting this error.在收到此错误之前,我没有在代码中进行任何更改。

Here is the code that i use to get the collections:这是我用来获取 collections 的代码:

MongoCollection<Document> collection = conexion.getDatabase().getCollection("users");

And here is the connect method:这是连接方法:

MongoClientURI uri = new MongoClientURI(
                    "mongodb+srv://cagide_j:"mypassword"@bastaproject-vo5a5.gcp.mongodb.net/test?retryWrites=true&w=majority");
            this.mongoClient = new MongoClient(uri);
            this.database = mongoClient.getDatabase("bastaProject");

Ensure that your Mongo database server is running and if Mongo is running on a different machine, as it appears to be, that you are connected to the internet.确保您的 Mongo 数据库服务器正在运行,并且如果 Mongo 正在另一台机器上运行(看起来是这样),那么您已连接到 Internet。 I'm not familiar with mongo.net, but many database as a service or in the cloud DB services have features that allow only IP addresses that are whitelisted to connect.我不熟悉 mongo.net,但许多数据库即服务或云数据库服务具有仅允许连接白名单的 IP 地址的功能。 I've seen issues with dynamic IP addresses that suddenly cannot connect.我已经看到突然无法连接的动态 IP 地址问题。 You could also try increasing the timeout.您也可以尝试增加超时。

It's hard to say much more without more complete code.如果没有更完整的代码,很难说更多。

I often find that these issues are something simple, but not necessarily easy to find.我经常发现这些问题很简单,但不一定很容易找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM