Reputation: 2931
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());
}
}
}
Upvotes: 0
Views: 683
Reputation: 3769
You are reassigning the original iterator to the while() loop each iteration through.
Iterator i = list.iterator();
while(i.hasNext()) {
....
}
Upvotes: 2