我正在使用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")
。
是否可以通过点运算符获取子文档?