简体   繁体   English

Casbah Scala MongoDB驱动程序 - 嵌入式对象

[英]Casbah Scala MongoDB driver - embedded objects

I know that objects in MongoDB can contain multiple levels of data (just the way JSON objects can). 我知道MongoDB中的对象可以包含多个级别的数据(就像JSON对象的方式一样)。 However, the Casbah driver tutorial only covers the creation of "flat" objects, where there is just one level of data. 但是,Casbah驱动程序教程仅涵盖“平面”对象的创建,其中只有一个级别的数据。 How can I create and work with multilevel objects with Casbah? 如何使用Casbah创建和处理多级对象?

Its pretty intuitive. 它非常直观。

construction: 施工:

val a: MongoDBOBject = DBObject("a" -> DBObject("b" -> "c"))
// results in { "a" : { "b" : "c"}}

access to inner fields with dot notation : 使用点表示法访问内部字段:

val c = a.expand[String]("a.b")

retrieval of inner object as DBObject, so you can make the same operations with it as with parent object: 将内部对象检索为DBObject,因此您可以使用它与父对象进行相同的操作:

val b = a.as[DBObject]("a")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM