val db = mongoClient("test")
val coll = db("test")
val q = MongoDBObject("id" -> 100)
val result= coll.findOne(q)
How can I convert result
to a map of key --> value pairs?
val db = mongoClient("test")
val coll = db("test")
val q = MongoDBObject("id" -> 100)
val result= coll.findOne(q)
How can I convert result
to a map of key --> value pairs?
Copyright © 2021 Jogjafile Inc.
result of findOne is an Option[Map[String, AnyRef]] because MongoDBObject is a Map. A Map is already a collection of pairs. To print them, simply:
or
To serialize mongo result, try
com.mongodb.util.JSON.serialize
, like