【问题标题】:MongoDB Document existsMongoDB 文档存在
【发布时间】:2016-02-09 18:21:50
【问题描述】:

如何检查 MongoDB v3 (Java) 中是否存在文档?

在“forEach”中我不能返回true,因为它本身就是一个void

    public static boolean exists(UUID uuid) {
    Main.getMongo().getCollection("players").find(new Document("uuid", uuid.toString())).forEach(new Block<Document>() {
        public void apply(Document document) {
            return true;
        }
    });
}

【问题讨论】:

    标签: java mongodb


    【解决方案1】:

    (编辑)相关但可能不是答案:

    请参阅以下内容,其中提供了一些替代方案,具体取决于您检查存在的原因。

    java mongo driver 3.0+

    【讨论】:

    • 这不是答案。请在评论中写下相同的内容。
    猜你喜欢
    • 1970-01-01
    • 2020-01-28
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    • 2014-09-29
    • 2021-11-07
    • 2021-11-21
    相关资源
    最近更新 更多