【发布时间】:2020-04-10 16:05:26
【问题描述】:
在 Java 中使用 MongoDB API 时,我试图在如下所示的文档中检索 two 的值:
data-id: "1234"
one:
two: "three"
我正在运行这个:
MongoCollection<Document> documents = ...;
Document document = documents.find(Filters.eq("data-id", "1234")).first(); // Not null
document.get("one"); // Not null
document.get("one.two"); // This is null
((Document) document.get("one")).get("two"); // Not null
在花了一些时间阅读文档和其他 Stack Overflow 问题后,我了解到在键名中使用点(例如 one.two 表示键)应该可以,但它不适合我。
【问题讨论】:
标签: java mongodb mongodb-java