I want to store a simple array of latitude,longitude inside a mongoDB collection using java and I am using following code but my "loc" array always is empty :
BasicDBObject doc = new BasicDBObject();
//doc.put("key " , r.getKey());
doc.put("category" , r.getKey());
doc.put("type" , r.getValue());
BasicDBObject latlon = new BasicDBObject();
ArrayList<Float> aLatLong = new ArrayList<Float>();
{
Float fLat = Float.parseFloat(r.getLatitude());
Float fLon = Float.parseFloat(r.getLongitude());
aLatLong.add(fLat);
aLatLong.add(fLon);
latlon.put("lat" , fLat);
latlon.put("lon" , fLon);
}
doc.put( "loc" , aLatLong);
but when I don't use ArrayList at all and try to store latlon into "loc" it will show me the data but its not an array anymore.
how can I save a simple array in mongoDB?