我遇到一个问题,它说我的连接已关闭,但我从未关闭过它。当我尝试获取集合时会发生这种情况。下面是所需的代码,我使用 MongoDB 的唯一其他时间是获取不同的集合并循环访问一些文档。
MongoCollection<Document> playerdb = db1.getCollection("Player");
Document playerDoc = playerdb.find(eq("uuid", p.getUniqueId().toString()))
.projection(Projections.fields(Projections.include("guildName")))
.first();
playerdb.updateOne(playerDoc, Updates.set("guildName", name))
```
The error is on the .first() method.
我认为 MongoClient 可能会关闭。使用文档之前