scala - Convert Casbah findOne to Map -
val db = mongoclient("test") val coll = db("test") val q = mongodbobject("id" -> 100) val result= coll.findone(q)
how can convert result
map of key --> value pairs?
result of findone option[map[string, anyref]] because mongodbobject map. map collection of pairs. print them, simply:
for { r <- result (key,value) <- r } yield println(key + " " + value.tostring)
or
result.map(_.map({case (k,v) => println(k + " " + v)}))
to serialize mongo result, try com.mongodb.util.json.serialize
, like
com.mongodb.util.json.serialize(result.get)
Comments
Post a Comment