Skip to content

Instantly share code, notes, and snippets.

@kornysietsma
Created August 9, 2011 05:48
Show Gist options
  • Save kornysietsma/1133478 to your computer and use it in GitHub Desktop.
Save kornysietsma/1133478 to your computer and use it in GitHub Desktop.
Mongo samples - scala
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