title: Distinct Query in Mongo using Java Mao Access Pattern
body: <p>I want to run a distinct query in mongo db using the spring framework java API. The query is something  like this :</p>
  
  <pre><code>db.location.distinct("state");
  </code></pre>
  
  <p>How do I create the Query object for the above. Below is a bad try.</p>
  
  <pre><code>import org.springframework.data.mongodb.core.query.Query;
  
  public List&lt;Location&gt; getLocations(int skipCount, int pageSize) 
  {
          Query query = new Query(Criteria.where("state").is("distinct);
          return mongoOperations.find(query, Location.class);
          /*
           Don't want to do the below, as using Mao Pattern  --
           DBCollection collection = db.getCollection("location");
           DBObject o1 = new BasicDBObject();
           List list = collection.distinct("state", o1);
           return list;
         */
  }
  </code></pre>