Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 0.80 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. mongodb casbah and list handling
  2. def findByHash(hash: Hash) = {
  3.         val dbobj = mongoColl.findOne(MongoDBObject("hash" -> hash.hashStr))
  4.         val n = dbobj match {
  5.             case Some(doc: com.mongodb.casbah.Imports.DBObject) => {
  6.                 doc("n") match {
  7.                     case Some(n: com.mongodb.casbah.Imports.DBObject) => {
  8.                         Some(List[String]() ++ n map { x => x.asInstanceOf[String] })
  9.                     }
  10.                     case _ => {
  11.                         None  // hash match but no n in object
  12.                     }
  13.                 }
  14.             }
  15.             case _ => {
  16.                 None  // no hash match
  17.             }
  18.         }
  19.         n
  20. }
  21.        
  22. val n = doc("n").asInstanceOf[BasicDBList]
  23. Some(List[String]() ++ n map { x => x.asInstanceOf[String] })