MongoDB文档:有没有一种方法可以获取带有点的子文档?

时间:2018-06-29 13:06:22

标签: java mongodb document mongo-java-driver

我正在使用mongodb,它是最新的Java驱动程序,我想要一种方便的方法来获取子文档

    Document d = Document.parse("{ parent : { child : 'foo'} }"); // d could be the result of a findOne query

    // I can't do this -- would be very convenient
    LOG.debug("Broken child value : " + d.getString("parent.child")); // shows null

    // I must do this -- very inconvenient
    LOG.debug("Child value : " + ((Document) d.get("parent")).getString("child")); // shows foo

要获取子文档,我必须使用不方便的((Document) d.get("parent")).getString("child")
是否可以通过点运算符获取子文档?

0 个答案:

没有答案
相关问题