title: Spring Data MongoDB. Custom @Query with current date
body: <p>I want to find all documents for last 2 hours.</p>
  
  <pre><code>@Repository
  public interface EventRepository extends MongoRepository&lt;Event, Long&gt; {
  
      @Query("{'createdAt': {$gt: new Date(ISODate().getTime() - 1000 * 60 * 60 * 2)}}")
      List&lt;Event&gt; findLive();
  
  }
  </code></pre>
  
  <p>But there is an error:</p>
  
  <pre><code>09-30 14:06:33 WARN org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'actionController' defined in file [/Users/serge/projects/bb/bb-whlive/target/classes/bb/whlive/controller/ActionController.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eventService' defined in file [/Users/serge/projects/bb/bb-whlive/target/classes/bb/whlive/service/EventService.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eventRepository': Invocation of init method failed; nested exception is com.mongodb.util.JSONParseException: 
  {'createdAt': {$gt: new Date(ISODate().getTime() - 1000 * 60 * 60 * 2)}}
                   ^
  </code></pre>
  
  <p>I know how to do it via MongoTemplate. But is it possible to do it via MongoRepository?</p>
  
  <p>P.S. In mongo shell this query works fine:</p>
  
  <pre><code>db.events.find({'createdAt': {$gt: new Date(ISODate().getTime() - 1000 * 60 * 60 * 2)}}).pretty();
  </code></pre>