title: Java, MongoDB Convert Cursor to an Array
body: <p>I'm using MongoDB with the Java driver. </p>
  
  <p>I've written a query that finds the minimum year for each region in the data. </p>
  
  <p>Full code:</p>
  
  <pre><code>public void minYearPerRegion() {
      for (int i = 0; i &lt; uniqueRegions.size(); i++) {
          BasicDBObject query = new BasicDBObject("Region", uniqueRegions.get(i));
          BasicDBObject field = new BasicDBObject("Year", 1)
                                                  .append("Region", 1)
                                                  .append("Population", 1);
  
  
          cursor = coll.find(query,field).sort(new BasicDBObject("Year",1)).limit(1);
          try {
              List&lt;DBObject&gt; documents = new ArrayList&lt;DBObject&gt;();
              for (DBObject dbObject : cursor) {
  
                  DBObject o = cursor.next();
                  documents.add(o);
              }
              System.out.println("Document contains: " + documents.size() + " document/s");
  
          } finally {
              cursor.close();
          }//end finally
      }//end for
  }//end minYearPerRegion
  </code></pre>
  
  <p>I'm trying to store my findings as individual documents but the cursor seems to present it as object.
  I've tried to split the object doing the following:</p>
  
  <pre><code>List&lt;DBObject&gt; documents = new ArrayList&lt;DBObject&gt;();
      for (DBObject dbObject : cursor) {
          DBObject o = cursor.next();
          documents.add(o);
      }
      System.out.println("Document contains: " + documents.size() + " document/s");
  </code></pre>
  
  <p>However the print line always says the documents list only contains one documents when it should contain 4 (as there are 4 unique regions).</p>
  
  <p>Please tell me how to get each document individually from the cursor and store it in an Array or List.</p>