title: How to convert MongoDB results from $dateToString operation to Java object
body: <p>I have obtained "date only" results from ISODate datatype from my mongo document using following query : </p>
  
  <pre><code>db.getCollection('tournamentactivity').aggregate( [ 
  {
      $project:{
              "yearMonthDay": 
                  { 
                      "$dateToString" : 
                      { 
                          "format" : "%Y-%m-%d", 
                          "date" : "$activityDate" 
                      } 
                  },                   
                  "tid" : 1,
                  "dayActivity.type" : 1    
             }
   },
   {
       $match:{
            $and : [
              { "tid" : "12345678" },
              { "yearMonthDay" : "2017-11-05" }             
           ]
  
  
        }      
  }] )
  </code></pre>
  
  <p>All good till here. But I am trying to convert the same in Java object as I have to send the same in my response type.</p>
  
  <p>I have followed this tutorial : <a href="http://www.baeldung.com/spring-data-mongodb-projections-aggregations" rel="nofollow noreferrer">Projections</a> and tried to do the same in my Java code as below : </p>
  
  <pre><code>ProjectionOperation projectToMatchModel = project().
              andExpression("format").as("%Y-%m-%d").
              andExpression("date").as("$activityDate");
  </code></pre>
  
  <p>I have written Aggregation operations prior to this, but I have no idea how to convert this result/query in Java code.</p>
  
  <p>Can anyone guide me where am I going wrong and how to use the same in 
  <em>Aggregation aggregation = newAggregation(
              );</em> method ?</p>
  
  <p>Thanks.</p>
  
  <p><strong>FYI</strong> : I have no idea on converting this query in my aggregation object and I <strong>might</strong> be wrong on choice of projection operations. Please go easy on me if I am wrong !</p>