title: JAVA MongoDB query to select distinct group of fields
body: <p>I have a MongoDB collection named "valuesCollection" whose fields are :
  <code>_id</code>, <code>cname</code>, <code>pname</code>, <code>timestamp</code>, <code>value</code></p>
  
  <p>In SQL, the query I would do is:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT DISTINCT(pname, cname) 
      FROM valuesCollection
          WHERE (timestamp &gt;= fromValue and timeStamp &lt;= toDate)
          GROUP BY cname, pname
  </code></pre>
  
  <p>For MongoDB in my Java code, I wrote :</p>
  
  <pre class="lang-java prettyprint-override"><code>
      AggregateIterable&lt;Document&gt; parameters = valuesCollection.aggregate(
                  Arrays.asList(
                      Aggregates.match(Filters.gte(MongoDBConstants.ROW_TIMESTAMP, fromDate)),
                      Aggregates.match(Filters.lte(MongoDBConstants.ROW_TIMESTAMP, toDate)),
                      Aggregates.group(MongoDBConstants.ROW_CNAME),
                      Aggregates.group(MongoDBConstants.ROW_PNAME)
                  )
              );
  </code></pre>
  
  <p>But the result is empty.
  What is wrong in my MongoDB query ?
  Thanks a lot for your help!</p>