I have got a database filled with documents like the following :
{
"_id" : ObjectId("56zeffb2abcf7ff24b46"),
"id_thing" : -1,
"data" : {
"info1" : 36.0709427,
"date" : ISODate('2005-11-01T00:33:21.987+07:00'),
"info2" : 24563.87148077
}
}
My find
method returns a List
which I operate some operations over:
for (d <- result_of_find_method_here)
{
val l_d = d("data")
}
But I would like to l_d
a List
which is currently not, and the toList
method does not work.
How do I retrieve all the fields and their value of the data
container as a list?
EDIT:
I have tried multiple methods, and none work because neither applies to AnyRef
which is what I get when I iterate through the l_d
with a foreach
loop.
Find method returns a list because there are more objects returned.
l_d
is not a list, because d['data']
is not a list is a key value store: a dictionary, json or map in Scala. The question is how do you want to represent this data?
Maybe you want to take out the values from the map as a list.
You can convert map to list using: l_d.toList
or map values to list: l_d.values.toList