title: Mongo aggregate using java
body: <p>Here is my command line code in Mongo client, But I do not know how to implement them using java sdk. Here i want to use mongoTemplate. Can someone help me?</p>
  
  <pre><code>db.getCollection('metrics.value').aggregate([{
      $match: {
          'serviceId': 85,
          'metricTimestamp': {
              $gte: ISODate("2018-02-03T04:33:58"),
              $lte: ISODate("2018-02-05T04:33:58")
          }
      }
  }, {
      $group: {
          _id: {
              $arrayElemAt: ["$metricValues", 0]
          },
          count: {
              $push: {
                  $arrayElemAt: ["$metricValues", 1]
              }
          }
      }
  }])
  </code></pre>
  
  <p>Aggregation agg = new Aggregation( match(Criteria.where("serviceId").in(serviceId).andOperator(Criteria.where("metricTimestamp").gte(startDate), Criteria.where("metricTimestamp").lte(endDate))), group()); </p>