Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created June 17, 2011 08:09
Show Gist options
  • Save xuwei-k/1031057 to your computer and use it in GitHub Desktop.
Save xuwei-k/1031057 to your computer and use it in GitHub Desktop.
casbah2.1.5-1で、DBからDynamicDBObjectで取得する場合のコード
import com.mongodb.casbah.Imports._
import com.mongodb.casbah.dynamic._
val db = MongoConnection("IPアドレスとか")("データベース名")
val col = db("コレクション名")
implicit def dynamicConverter(obj:DBObject) = new {
def toDynamic = DynamicDBObject.empty ++= obj
}
val obj = col( DBObject("name" -> "Scalaちゃん") ).toDynamic
println( obj.得意呪文.typed[String].getOrElse("得意呪文なし") )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment