title: Spring mongo repository sort descending by a certain property
body: <p>I want to sort Descending by lastChange property, the List of items from mongo.</p>
  
  <p><strong>RequestRepository interface:</strong></p>
  
  <pre><code>public interface RequestRepository extends MongoRepository&lt;Request, String&gt; {
      List&lt;Request&gt; findByUser(String id);
  }
  </code></pre>
  
  <p>Request.java:</p>
  
  <pre><code>@Document(collection = "Requests")
  public class Request {
  
  @Id
  private String id;
  private String user;
  private String username;
  private String requestTitle;
  private String requestMessage;
  private boolean read;
  private Date lastChange;
  private Date requestDate;
  private boolean isActiveRequest;
  private boolean isPremiumRequest; //paid request
  
  public Request() {}
  
  public Request(
          String user,
          String requestTitle,
          String requestMessage,
          boolean read,
          Date lastChange,
          Date requestDate,
          boolean isActiveRequest) {
      this.user = user;
      this.requestTitle = requestTitle;
      this.requestMessage = requestMessage;
      this.read = read;
      this.lastChange = lastChange;
      this.requestDate = requestDate;
      this.isActiveRequest = isActiveRequest;
  }
  
  public String getId() {
      return id;
  }
  
  public void setId(String id) {
      this.id = id;
  }
  
  public String getUser() {
      return user;
  }
  
  public void setUser(String user) {
      this.user = user;
  }
  
  public String getUsername() {
      return username;
  }
  
  public void setUsername(String username) {
      this.username = username;
  }
  
  public String getRequestTitle() {
      return requestTitle;
  }
  
  public void setRequestTitle(String requestTitle) {
      this.requestTitle = requestTitle;
  }
  
  public String getRequestMessage() {
      return requestMessage;
  }
  
  public void setRequestMessage(String requestMessage) {
      this.requestMessage = requestMessage;
  }
  
  public boolean isRead() {
      return read;
  }
  
  public void setRead(boolean read) {
      this.read = read;
  }
  
  public Date getLastChange() {
      return lastChange;
  }
  
  public void setLastChange(Date lastChange) {
      this.lastChange = lastChange;
  }
  
  public Date getRequestDate() {
      return requestDate;
  }
  
  public void setRequestDate(Date requestDate) {
      this.requestDate = requestDate;
  }
  
  public boolean isActiveRequest() {
      return isActiveRequest;
  }
  
  public void setActiveRequest(boolean activeRequest) {
      isActiveRequest = activeRequest;
  }
  
  public boolean isPremiumRequest() {
      return isPremiumRequest;
  }
  
  public void setPremiumRequest(boolean premiumRequest) {
      isPremiumRequest = premiumRequest;
  }
  }
  </code></pre>
  
  <p>In my code I have the following list:</p>
  
  <pre><code>List&lt;Request&gt; = RequestRepository.findByUser(userObj.getId());
  </code></pre>
  
  <p>I want to have the data from <code>RequestRepository.findByUser(userObj.getId());</code> sorted DESCENDING by the property <code>lastChange</code>. </p>
  
  <p>I have searched on StackOverflow, and found the following method to sort:</p>
  
  <pre><code>List&lt;Request&gt; findAllByOrderByUpdatedAtDesc();
  </code></pre>
  
  <p>but this does not work if I search by User.</p>
  
  <p>What is the solution to search by User id and to sort by <code>lastChange</code>?</p>
  
  <p>Thank you!</p>