user2572739 user2572739 - 3 days ago 4
Java Question

DBObject to Map in java

I need to put the result from MongoDB in Map. My code is

DBCollection collection = db.getCollection("template");
DBCursor cursor = collection.find(allQuery, removeIdProjection);
DBObject resultElement = null;
resultElement = cursor.next();


and the result Json is:


{ "GraphLabel" : "Volume Of Work Orders" , "XaxisLabel" : "2012" ,
"YaxisLabel" : "volume(k)" , "ShowLegend" : "FALSE" , "query" :
"select sd.season_id,sd.season, count(fsf.defect_type_id) from
m2m.season_dim sd ,m2m.field_service_fact fsf where fsf.season_id =
sd.season_id group by sd.season_id"}


Need to put the values with MAP or POJO .. Can somebody help please?

Answer

The DBObject has a toMap() method which transforms it into map

Comments