title: Mongo match in aggregate not working for date using java
body: <p>I am using mongoDB java driver to query transactions between date range with aggregate framework. I am trying to use following mongo query:</p>
  
  <pre class="lang-js prettyprint-override"><code>db.orders.aggregate([
  { "$match":{
      "order_commit_time": {
          "$gte": ISODate("2015-04-30T18:30:00.000Z"),
          "$lte": ISODate("2016-08-23T19:53:23.000")
      }
  }
  },
  {
  "$unwind": "$discounts_list"
  }, {
  "$unwind": "$discounts_list.discount_split"
  }, {
  "$group" :{
      "_id": null,
      count:{$sum:1}
  }
  }]
  );
  </code></pre>
  
  <p>The java code I am using to make query is following:</p>
  
  <pre class="lang-java prettyprint-override"><code>Date startDate = new Date(period.getStartTime().getTimeInMillis());
  Date endDate = new Date(period.getEndTime().getTimeInMillis());
  
  BasicDBObject match = new BasicDBObject("$match", new BasicDBObject(mongoDateField, 
      new BasicDBObject("$gte", startDate).append("$lte", endDate)));
  BasicDBObject discount_list = new BasicDBObject("$unwind", "$discounts_list");
  BasicDBObject discount_split = new BasicDBObject("$unwind", "$discounts_list.discount_split");
  BasicDBObject group = new BasicDBObject("$group", new BasicDBObject("_id", null)
      .append("count", new BasicDBObject("$sum", 1)));
  AggregationOutput output = mongoCollection.getCollection().aggregate(match, discount_list, discount_split, group);
  </code></pre>
  
  <p>But this java query is returning empty result. However if I use the mongo query on console, it is working fine. Also if I remove match from aggregation, query works fine but don't filter the result according to date. Moreover the same "match" DBObject, when used in count or find as query, works fine like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>query = new BasicDBObject(mongoDateField, new BasicDBObject("$gte", startDate).append("$lte", endDate));
  mongoCount = mongoCollection.getCollection().count(query);
  </code></pre>
  
  <p>Is there any way to convert the mongo query to java equivalent.</p>
  
  <p>Thanks in advance.</p>