title: Finding distinct from collections in mongodb
body: <p>Our previous implementation for finding distinct elements from a collection used to be :</p>
  
  <pre><code>List&lt;String&gt; names = mongoClient.getDB(dbName).getCollection(collectionName).distinct(NAME_KEY);
  </code></pre>
  
  <p>Trying to upgrade this into the current implementation with mongo 3.3.0+ as tried is : </p>
  
  <pre><code>List&lt;String&gt; names = mongoClient.getDatabase(dbName)
                          .getCollection(collectionName, TDocType.class)
                          .distinct(NAME_KEY, String.class); // compile error - required Class&lt;TResult&gt; 
  </code></pre>
  
  <p>Have also given a try to   </p>
  
  <pre><code>.distinct(NAME_KEY, TDocType.class)  // doesn't work                      
  </code></pre>
  
  <p>What shall be the target type of the iterable in this case?</p>
  
  <p><strong><em>Edit</em></strong> - The question is not a duplicate of <a href="https://stackoverflow.com/questions/20655506/get-distinct-records-values">Get distinct records values</a> since the implementation has changed over the upgrade of <code>mongodb-java-driver</code>.</p>