title: mongodb 3 java: aggregation sum of keys
body: <p>I have collection which is have _id and searchKey . I want to know count of each stored key like "java 2, C++ 3 " .
  My entity is </p>
  
  <pre><code>public class SearchKeyModel implements Serializable {
  
      private static final long serialVersionUID = 2099119595418807689L;
  
      private String searchKey;
      private Integer count;  
  </code></pre>
  
  <p>Aggregation like this:</p>
  
  <pre><code>Iterator&lt;Document&gt; sortedList = collection
              .aggregate(Arrays.asList(new Document("$match", new Document("searchKey", 1)),
                      new Document("$sort", new Document("count", -1)),
                      new Document("$group", new Document("_id", null).append("count", new Document("$sum", 1)
                      ))
              )).iterator();
  
      System.out.println("list hasNext " + sortedList.hasNext());
  
      while (sortedList.hasNext()) {
          Document doc = sortedList.next();
          SearchKeyModel entity = gson.fromJson(doc.toJson(), SearchKeyModel.class);
          list.add(entity);
      }
          System.out.println("list size is " + list.size());
  </code></pre>
  
  <p>But sortedList.hasNext() always false.</p>
  
  <p>Can anyone help to understand how to finish this?</p>