Created
June 17, 2012 03:02
-
-
Save gkojax/2943264 to your computer and use it in GitHub Desktop.
mongoからcollection.findで取ってきたデータはtoListしないとListにならないのわかってなかった
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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