Casbah Scala MongoDB driver - embedded objects

casbah, mongodb, scala

Solution

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:

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

Problem

I know that objects in MongoDB can contain multiple levels of data (just the way JSON objects can). However, the Casbah driver tutorial only covers the creation of "flat" objects, where there is just one level of data. How can I create and work with multilevel objects with Casbah?

Original source