title: Query with sort() and limit() in Spring Repository interface
body: <p>I'm new to Spring Data with MongoDB and would like to have an automagically generated query method inside my MongoRepository extension interface which requires filtering, sorting and limiting. </p>
  
  <p>The query looks like this:</p>
  
  <pre><code>// 'created' is the field I need to sort against
  
  find({state:'ACTIVE'}).sort({created:-1}).limit(1)
  </code></pre>
  
  <p>The repository interface looks like this:</p>
  
  <pre><code>public interface JobRepository extends MongoRepository&lt;Job, String&gt; {
      @Query("{ state: 'ACTIVE', userId: ?0 }")
      List&lt;Job&gt; findActiveByUserId(String userId);
  
      // The next line is the problem, it wont work since
      // it's not in the format @Query expects
      @Query("find({state:'ACTIVE'}).sort({created:-1}).limit(1)")
      Job findOneActiveOldest();
  
      ...
  }
  </code></pre>
  
  <p>I know that one can add a Sort argument to a query method in order to get sorting but the problem is limiting the results to just a single object. Is this possible to do without having to write a custom JobRepositoryImpl?</p>
  
  <p>Thanks</p>
  
  <p>Edit:</p>
  
  <p>Example of what I am looking for:</p>
  
  <pre><code>@Query("{ state:'ACTIVE', $orderby: {created:-1}, $limit:1 }")
  Job findOneActiveOldest();
  </code></pre>
  
  <p>or</p>
  
  <pre><code>@Query("{ state:'ACTIVE' }")
  @Sort("{ created:-1 }")
  @Limit(1)
  Job findOneActiveOldest();
  </code></pre>
  
  <p>But this obviously doesn't work :(</p>