When I try to put this type1 array from mongoDB document , I can take that as an array through java by doing code like :
BasicDBList listEditionsAssets = (BasicDBList) nextAssets.get("areas");
following is type1 array :
{
"ClientId" : "212",
"UserId" :"212",
"areas" : [
{
"Area 1" : "Chicago"
"Area 2" : "LA",
"Area 3" : "Boston"
]
}
But,following is the data I have in mongoDB document :
following is 'type2' array :
{
"ClientId" : "212",
"UserId" :"212",
"areas" : ["Chicago","LA","Boston" ]
}
When I try to retrieve "areas" array in java by using BasicDBList, it comes as "null". Because java is taking it as String. When I take it as
BasicDBObject result = (BasicDBObject) it.next();
String areas = (String) result.get("areas");
I can read is as String.
So how can I read "areas" in type2 document as an Array in java and not the String ?
type2.areasis an array? I've tested on my local withmongo-java-driver 3.4.2. It does return a list with(List) dbObject.get("areas"){ "areas" : ["1", "2"] }and the result of above get with list casting ->["1", "2"]