Skip to content

Instantly share code, notes, and snippets.

@saml
Created March 18, 2013 15:17
Show Gist options
  • Save saml/5187895 to your computer and use it in GitHub Desktop.
Save saml/5187895 to your computer and use it in GitHub Desktop.
object MongoDBUtils {
private def getAsRec[T: Manifest](dbo: MongoDBObject, keys: List[String]): Option[T] = keys match {
case Nil => None
case key :: Nil => dbo.getAs[T](key)
case key :: rest => dbo.getAs[DBObject](key).flatMap(doc => getAsRec[T](doc, rest))
}
def getAs[T:Manifest](dbo: MongoDBObject, key: String): Option[T] = getAsRec[T](dbo, key.split('.').toList)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment