0

I am reading MongoDB results using the following code , however the while loop runs in an infinite loop always iterating over the first element in the collection, can someone point out what I am doing wrong.

       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());
                }

            }
        }
user1965449
  • 2,849
  • 6
  • 34
  • 51

1 Answers1

2

You are reassigning the original iterator to the while() loop each iteration through.

Iterator i = list.iterator();
while(i.hasNext()) {
  ....
}
Rick Mangi
  • 3,761
  • 1
  • 14
  • 17