I am using Scala and Mongoldb-Casbah and I get some data with:
val myData: Traversable[Imports.DBObject] = myCollection.find(query).toTraversable
The data returned are a collection like this:
[ { _id:"...", prices:[ {myValue:"...",...}, {myValue:"...",...},... ] }, {... },... ]
What I need to get, it is the first not empty myValue
.
I tried different things like:
myData.foldLeft(List[Any]()) { (acc, v) =>
acc ++ v.get("prices").asInstanceOf[BasicDBList].filter(_.asInstanceOf[DBObject].getOrElse("myValue", "").toString.nonEmpty).take(1)
}
but it is not returning one single value unless I make it even more complicated. I didn't tried findMap
or collectFirst
yet tho.
Any idea how to extract one single myValue
from that data?