Created
May 17, 2011 20:22
-
-
Save bwmcadams/977298 to your computer and use it in GitHub Desktop.
Dynamic Casbah Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.mongodb.casbah.Imports._ | |
import com.mongodb.casbah.dynamic._ | |
val d = DynamicDBObject("_id" -> new ObjectId, "name" -> "Brendan McAdams", | |
"address" -> MongoDBObject("street" -> "134 5th Ave Fl 3", | |
"city" -> "New York", | |
"state" -> "NY", | |
"zip" -> 10011), | |
"email" -> "[email protected]") | |
d.name.typed[String] | |
// res4: Option[String] = Some(Brendan McAdams) | |
d.name.typed[Int] | |
// res5: Option[Int] = None | |
d.address.city.typed[String] | |
// res6: Option[String] = Some(New York) | |
d.address.zip.typed[Int] | |
// res7: Option[Int] = Some(10011) | |
d.address.zip.typed[String] | |
// res8: Option[String] = None | |
d.address.typed[DBObject] | |
// res9: Option[com.mongodb.casbah.Imports.DBObject] = Some({ "street" : "134 5th Ave Fl 3" , "city" : "New York" , "state" : "NY" , "zip" : 10011}) | |
d.foo.bar.baz.bang.more.stuff.that.dont.exist.typed[String] | |
// res10: Option[String] = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment