title: Spring Boot, MongoDB, Pageable, sort by a custom method in the object
body: <p>Say for example I have the following setup,</p>
  
  <p>A model like this:</p>
  
  <pre><code>public class Post {
  
      @Id
      private String id;
      private String post;
      private List&lt;Vote&gt; votes = new ArrayList&lt;&gt;();
  
      // Getters &amp; Setters...
      public double getUpVotes() {
          return votes.stream().filter(vote -&gt; vote.getDirection() == 1).mapToInt(Vote::getDirection).count();
      }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>public class Vote {
  
      private short direction;
  
      // Getters &amp; Setters...
  }
  </code></pre>
  
  <p>and then a repository like this</p>
  
  <pre><code>@Repository
  public interface PostRepository extends PagingAndSortingRepository&lt;Post, String&gt; {
  
      List&lt;Post&gt; findAll(Pageable pageable);
  }
  </code></pre>
  
  <p>And say I want to sort the posts by the result of the getter method <code>getUpVotes()</code></p>
  
  <p>I've tried the following <code>localhost:3005/opinion?page=0&amp;size=20&amp;sort=upVotes</code> but its doesn't work.</p>