title: Create a list from DbCursor in MongoDB and Java
body: <p>I am trying to use a cursor to iterate over documents, i want to store them in a list,and later on return a list of type DBOject.</p>
  
  <p>Here is what I am trying:</p>
  
  <pre><code>public List&lt;DBObject&gt; getResultsInDescendingOrderByDate(int limit) {
  
          List&lt;DBObject&gt; myList = null;
          DBCursor myCursor=myCollection.find().sort(new BasicDBObject("date",-1)).limit(10);
          try {
          while(myCursor.hasNext()) {
  
                  System.out.print(myCursor.next());
                 myList.add(new BasicDBObject("_id",(String) myCursor.curr().get("_id"))
                          .append("title",(String) myCursor.curr().get("title"))
                          .append("author",(String) myCursor.curr().get("author"))
                          .append("permalink",(String) myCursor.curr().get("permalink"))
                          .append("body",(String) myCursor.curr().get("body"))
                          .append("comment",new BasicDBObject("comments",(String) myCursor.curr().get("comments")))
                                  .append("tags",new BasicDBObject("tags",(String) myCursor.curr().get("tags"))
                                  .append("date",(Date) myCursor.curr().get("date"))));
                  myCursor.next();
              }
          }
  
          finally {
              myCursor.close();
          }
  
  
          return myList;
      }
  </code></pre>
  
  <p>I don't know how to convert the data type into a primitive one form the cursor. I tried searching,but no clues.</p>
  
  <p>Please help.</p>
  
  <p>Thanks</p>