title: MongoDB Java API slow reading peformance
body: <p>We are reading from a local MongoDB all documents from a collections and performance is not very brillant.</p>
  
  <p>We need to dump all the data, don't be concerned why, just trust it's really needed and there is no workaround possible.</p>
  
  <p>We've 4mio documents that look like :</p>
  
  <pre><code>{
      "_id":"4d094f58c96767d7a0099d49",
      "exchange":"NASDAQ",
      "stock_symbol":"AACC",
      "date":"2008-03-07",
      "open":8.4,
      "high":8.75,
      "low":8.08,
      "close":8.55,
      "volume":275800,
      "adj close":8.55
  }
  </code></pre>
  
  <p>And we're using this for now trivial code to read:</p>
  
  <pre><code>MongoClient mongoClient = MongoClients.create();
  MongoDatabase database = mongoClient.getDatabase("localhost");
  MongoCollection&lt;Document&gt; collection = database.getCollection("test");
  
  MutableInt count = new MutableInt();
  long start = System.currentTimeMillis();
  collection.find().forEach((Block&lt;Document&gt;) document -&gt; count.increment() /* actually something more complicated */ );
  long start = System.currentTimeMillis();
  </code></pre>
  
  <p>We're reading the whole collection at 16 seconds ( 250k row/sec), that is really not impressive at all with small documents. Bear in mind we want to load 800mio rows. No aggregate, map reduce or similar are possible.</p>
  
  <p>Is this as fast as MongoDB gets or are there other ways to load documents faster (other techniques, moving Linux, more RAM, settings...)? </p>