title: Sort and distinct Mongodb in Java 3.2
body: <p>I am having 80,000 documents in my mongodb. I am querying these documents using Java driver. I tried to sort my documents based on particular field then applying distinct filter to this result. Sort option works fine but I cant get distinct documents. I have attached my work examples.</p>
  
  <pre><code>    Document query = new Document("RetweetCount",-1);
      MongoCursor&lt;Document&gt; cursor = collection.find().sort(query).iterator();
      try{
      while(cursor.hasNext()) {
          Document dr = (Document) cursor.next();
          String stat = dr.getString("status");
          int retweetcount = dr.getInteger("RetweetCount");
          //Sort works fine. I have to apply distinct here!!! distinct is based on status field
          System.out.println(retweetcount+"---&gt;"+stat);
      }
      }finally{
          cursor.close();
      }
  }
  </code></pre>