3

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?

user2572739
  • 299
  • 5
  • 13

2 Answers2

9

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

Ori Dar
  • 18,687
  • 5
  • 58
  • 72
1

Below Code would do:

DBCollection collection = db.getCollection("template");
DBCursor cursor = collection.find(allQuery, removeIdProjection); 
Document doc = cursor.next(); // Which is already a Map compatible object

Map <String, Object> mDoc = doc;
Alex Stybaev
  • 4,623
  • 3
  • 30
  • 44
Andrews
  • 11
  • 1