Created
August 9, 2011 05:48
-
-
Save kornysietsma/1133478 to your computer and use it in GitHub Desktop.
Mongo samples - scala
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
val mongoConn = MongoConnection("camellia") | |
val people = mongoConn("people") | |
val fred = MongoDBObject("firstName" -> "Fred", | |
"lastName" -> "Bloggs", | |
"ssid" -> 8675309) | |
people += fred | |
val possiblyFred = people.findOne("firstName" -> "Fred", | |
"lastName" -> "Bloggs") | |
// possiblyFred: Option[MongDBObject] | |
val foundFred = possiblyFred.getOrElse( | |
throw new Exception("Can't find fred!")) | |
val fredSsid = foundFred.getAs[Integer]("ssid").getOrElse( | |
throw new Exception("Fred has no SSID!")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment