2013-08-27 27 views
2

我需要將Map中的MongoDB結果。我的代碼是在java中映射DBObject

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

,結果JSON是:

{ 「GraphLabel」: 「卷工作單」, 「XaxisLabel」: 「2012」, 「YaxisLabel」:「卷( k)「,」ShowLegend「:」FALSE「,」query「: 」selectsd.season_id group by sd.season_id「}

需要用MAP或POJO來表示數值。有人可以幫忙嗎?

+0

http://stackoverflow.com/questions/7684223/convert-dbobject-to的可能的複製-a-pojo-using-mongodb-java-driver –

+0

我不想使用Jackson ... – user2572739

回答

6

DBObjecttoMap()方法,將其轉換爲地圖

+0

謝謝Orid ..我正在嘗試它 – user2572739

0

下面的代碼會做:

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;