Skip to content

Instantly share code, notes, and snippets.

@gkojax
Created June 17, 2012 03:02
Show Gist options
  • Save gkojax/2943264 to your computer and use it in GitHub Desktop.
Save gkojax/2943264 to your computer and use it in GitHub Desktop.
mongoからcollection.findで取ってきたデータはtoListしないとListにならないのわかってなかった
package jp.ddo.loveless
import com.mongodb.casbah.Imports._
import net.liftweb.json._
object CasbahSample extends App {
val collection = MongoConnection("servername")("tumblr")("reblogdata")
val condition = MongoDBObject("count"->221)
case class Data(rk:String, count:Int)
val list = collection.find(condition).map{ x =>
val rk = x.getAs[String]("rk").getOrElse("no")
val count = x.getAs[Int]("count").getOrElse(0)
Data(rk, count)
}.toList
implicit val format = Serialization.formats(NoTypeHints)
val json = Serialization.write(list)
println(json)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment