title: Spring Mongo Paging with sorting with MongoRepository
body: <p>Document Structure - <strong>message{obj_id,post_id,message_time,message_text}</strong> and @key is <strong>obj_id</strong>.</p>
  
  <p>Problem Statement: I just want that fetch all the data contains  <strong>post_id: '<em>anything</em>'</strong> with sorts on the basis of <strong>message_time</strong> and want custom paging in the result every time. Now I am implementing code mentioned below according to <strong>link:</strong><a href="https://stackoverflow.com/a/10077534/9901300">https://stackoverflow.com/a/10077534/9901300</a>. But couldn't find where should I give different <strong>post_id</strong> every time to search result for.</p>
  
  <p>Please look over below code. </p>
  
  <pre><code>public interface MessageMongoRepository extends 
  MongoRepository&lt;Message, String&gt; {
  
  @Query("{ 'post_id' : ?0 }")
  Page&lt;Message&gt; findByPostIdSorted(Pageable pageable);
  }
  </code></pre>
  
  <p><strong>Service:</strong></p>
  
  <pre><code>@Override
  public List&lt;Message&gt; getByPostId(String PostId, int page, int size) {
      List&lt;Message&gt; messages = new ArrayList&lt;&gt;();
      @SuppressWarnings("deprecation")
      PageRequest request = new PageRequest(page, size, new Sort(Sort.Direction.DESC, "message_time"));
      messages = messageRepository.findByPostIdSorted(request).getContent();
      return messages;
  }
  </code></pre>