title: Spring data MongoDB get document closes to the give date and time
body: <p>I'm trying to implement the following working mongoDb query in Spring Data using MongoTemplate</p>
  
  <p>db.events.aggregate([</p>
  
  <pre><code>    { 
          "$match" : { 
              "someId" : "5bf5372d6518b0b6315d7a29"
          }
      }, 
      { 
          "$project" :{ 
              "totalValue" : 1, 
              "diff" : {
                  "$abs":{ 
                      "$subtract" : [ "$dateTime" ,  new Date(2018,11,21,9,0,0)]
                  }
              }
          }
      }, 
      {
          "$sort":{ 
              "diff":1
          }
      },
      {
          "$limit":1
      }
  ])
  </code></pre>
  
  <p>I have got upto this point </p>
  
  <pre><code>MatchOperation match = Aggregation.match(Criteria.where("someId").is("idValue"));
          ProjectionOperation projection = Aggregation.project().and("dateTime")
                  .minus(format.parse(LocalDate.now().toString() + " 09:00:00").getTime()).as("diff")
                  .and("totalValue").as("totalValue");
          SortOperation sort = Aggregation.sort(Sort.Direction.ASC, "diff");
          AggregationResults&lt;Document&gt; result = mongoTemplate
                  .aggregate(Aggregation.newAggregation(match, projection, sort), Input.class, Document.class);
  </code></pre>
  
  <p>Following is the documents</p>
  
  <pre><code>db.event.insert([
  {someId: "5bf5372d6518b0b6315d7a29", dateTime: new Date(2018,11,21,9,00,11), totalValue: .15},
  {someId: "5bf5372d6518b0b6315d7a29", dateTime: new Date(2018,11,21,9,00,01), totalValue: .05},
  {someId: "5bf5372d6518b0b6315d7a29", dateTime: new Date(2018,11,21,9,01,11), totalValue: .25},
  {someId: "5bf5372d6518b0b6315d7a29", dateTime: new Date(2018,11,21,9,01,51), totalValue: .45},
  {someId: "5bf5372d6518b0b6315d7a29", dateTime: new Date(2018,11,21,8,59,02), totalValue: .04},
  {someId: "5bf5372d6518b0b6315d7a29", dateTime: new Date(2018,11,21,8,55,11), totalValue: .95},
  {someId: "5bf5372d6518b0b6315d7a28", dateTime: new Date(2018,11,21,9,01,51), totalValue: .051},
  {someId: "5bf5372d6518b0b6315d7a28", dateTime: new Date(2018,11,21,8,59,02), totalValue: .041},
  {someId: "5bf5372d6518b0b6315d7a28", dateTime: new Date(2018,11,21,8,55,11), totalValue: .053},
  {someId: "5bf5372d6518b0b6315d7a29", dateTime: new Date(2018,11,22,8,59,02), totalValue: .974},
  {someId: "5bf5372d6518b0b6315d7a29", dateTime: new Date(2018,11,22,8,55,11), totalValue: .9},
  {someId: "5bf5372d6518b0b6315d7a28", dateTime: new Date(2018,11,22,9,01,51), totalValue: .151},
  {someId: "5bf5372d6518b0b6315d7a28", dateTime: new Date(2018,11,22,8,59,02), totalValue: .241}])
  </code></pre>
  
  <p>Expected output is : 0.05 (as it is close to the date time 21-11-2018 09:00:00)</p>