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?
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With