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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -