I am having difficulty extracting the value I need from MongoDBObject
Let's take this simple example
val mObj = MongoDBObject( "attributes" ->
MongoDBList(MongoDBObject("name"->"owner", "value"->"john"))
)
I want to obtain the "value" of the "owner" attribute.
I tried this
mObj.as[Seq[Map[String,Any]]]("attributes")
But, but the runtime types are not correct. The conversion only happens on the first level.
I tried
mObj.toMap
But, again this converts it to a java Map. Also, the conversion is shallow.
Last resort
mObj.as[MongoDBList]("attributes").as[DBObject](0).as[String]("value")
This worked. But, I am not still not sure how I can do a find on the List to look for the attribute name. Also, I am forced to use as[DBObject] instead of as[MongoDBObject].
We purposefully don't use only JSON data in the db (i.e no ObjectId, DBRef or Date etc). So, one option I am considering is converting the result to Json4s and work with that instead.
I am open to other suggestions.