我已返回3個結果解析AggregationOutput蒙戈Java驅動程序
{ "serverUsed" : "/127.0.0.1:27017" , "result" : [ { "_id" : "luke" , "times" : 56} , { "_id" : "albert" , "times" : 28} , { "_id" : "matt" , "times" : 28}] , "ok" : 1.0}
但是當我試圖遍歷結果,代碼進入無限循環合計(不明白爲什麼!!)
AggregationOutput output = coll.aggregate(match1, unwind, match2, group, sort, limit);
Iterable<DBObject> list= output.results();
while(list.iterator().hasNext()){
String id = (String) list.iterator().next().get("_id");
int times = Integer.parseInt(list.iterator().next().get("times").toString());
System.out.println("ID IS "+id+" time: "+times);
}
而且輸出重複的第一個結果:
ID IS luke time: 56
ID IS luke time: 56
ID IS luke time: 56
ID IS luke time: 56
ID IS luke time: 56
...
我真的不;噸明白爲什麼這個迭代不起作用。請幫忙!
每個作品!!!謝謝!我完全是FUSE工作太多:( – nuvio 2013-03-23 20:33:48
@nuvio不客氣,很高興幫助你!:) – tenorsax 2013-03-23 20:35:16