读取结果时,MongoDB Java Driver Infinite循环



我正在使用以下代码读取MongoDB结果,然而while循环在一个无限循环中运行,总是在集合中的第一个元素上迭代,有人能指出我做错了什么吗。

       Iterable<DBObject> list = playerData.results();
        if(list != null){
            while(list.iterator().hasNext()) {
                DBObject obj = list.iterator().next();
                DBObject id =  (DBObject) obj.get("_id");
                String player= obj.get("player").toString();
                //Populate the memcached here .
                PlayerDTO rcd = new PlayerDTO();
                if(id != null && id.get("venue" != null && id.get("score") != null) {
                    rcd.setVenue(id.get("venue").toString());
                    rcd.setScore(new Double(id.get("score").toString()).doubleValue());
                }
            }
        }

每次迭代都将原始迭代器重新分配给while()循环。

Iterator i = list.iterator();
while(i.hasNext()) {
  ....
}

最新更新