title: mongodb cursor exception - Java
body: <p>I am using mongodb to store information of users. 
  I wanted to create a method that get the information from the db, creates Player objects and inserts them in an array of Players.</p>
  
  <p>this is the following method</p>
  
  <pre><code>public ArrayList&lt;Player&gt; getArrayOfPlayers(){
      ArrayList&lt;Player&gt; savePlayers = new ArrayList&lt;Player&gt;();
      DB db = connectToMongo();
      DBCollection coll = db.getCollection("players");
      DBCursor cursor = coll.find();
  
          while(cursor.hasNext()) {
              String tempName = (String)cursor.next().get("name");
              String tempSession = (String)cursor.next().get("session");
              String tempStringScore = (String)cursor.next().get("score");
  
              int tempScore = Integer.parseInt(tempStringScore);
  
              Player player = new Player(tempName,tempSession,tempScore);
              savePlayers.add(player);
          }
  
  
      return savePlayers;
  }
  </code></pre>
  
  <p>I have 4 users stored in the db and when I 'm trying to first call the method and then print the names for example I'm getting an exception.
  I used a try-catch outside the method's while and I caught the exception, but then it printed the name of the first user only. It seems that it throws the exception in the second iteration. </p>
  
  <p>Here is the message with the exception that I am receiving.</p>
  
  <pre><code>java.lang.RuntimeException: no more
  com.mongodb.DBApiLayer$Result.next(DBApiLayer.java:394)
  com.mongodb.DBApiLayer$Result.next(DBApiLayer.java:360)
  com.mongodb.DBCursor._next(DBCursor.java:445)
  com.mongodb.DBCursor.next(DBCursor.java:525)
  machine.DAOMongodb.getArrayOfPlayers(DAOMongodb.java:74)
  machine.testDB.doGet(testDB.java:43)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  </code></pre>