3

我需要将 MongoDB 的结果放在 Map 中。我的代码是

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

结果Json是:

{ “GraphLabel”:“工单数量”,“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"}

需要将值与 MAP 或 POJO .. 有人可以帮忙吗?

4

2 回答 2

8

DBObject有一种将toMap()其转换为地图的方法

于 2013-08-27T10:33:58.023 回答
1

下面的代码会做:

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;
于 2016-12-01T09:34:28.167 回答