MongoDB java.lang.IllegalStateException:状态应该是:打开

问题描述 投票:0回答:1

我遇到一个问题,它说我的连接已关闭,但我从未关闭过它。当我尝试获取集合时会发生这种情况。下面是所需的代码,我使用 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.
java mongodb mongodb-query
1个回答
0
投票

我认为 MongoClient 可能会关闭。使用文档之前

© www.soinside.com 2019 - 2024. All rights reserved.