title: Java Spring : MongoRepository count() and findAll()
body: <p>I have noticed something weird in Spring data for mongo :  </p>
  
  <p><code>MongoRepository</code> extends <code>CrudRepository</code> and the <code>findAll()</code> returns an <code>Iterable</code> which it's ok with the <code>count()</code> method as it returns a <code>long</code>.</p>
  
  <pre class="lang-java prettyprint-override"><code>class CrudRepository {
  
    ...
  
    Iterable&lt;T&gt; findAll();
  
    long count();
  }
  </code></pre>
  
  <p>In mongo <code>MongoRepository</code> the <code>findAll()</code> method returs a <code>List</code> :</p>
  
  <pre class="lang-java prettyprint-override"><code>class MongoRepository extends CrudRepository {
  
    ...  
  
    @Override
    List&lt;T&gt; findAll();
  }
  </code></pre>
  
  <p>But a <code>List#size()</code> returns an <code>int</code> and the <code>MongoRepository#count()</code> method stay returning a long.</p>
  
  <p>What happens when the collection exceed <code>Integer.MAX_VALUE</code> !? Could we still call <code>List&lt;T&gt; findAll()</code> ?</p>