title: How to get last record in spring mongo?
body: <p>I have a transaction class which stores the each transaction of a customer,Following are the fields in this class.</p>
  <pre><code>class Transaction{
      @Id
      private String id;
      private Date date;
      private String customerId;
      private double openBalance;
      private double transctionAmount;
      private double finalAmount;
  
  }
  </code></pre>
  <p>I need to fetch only the last inserted record of a customer (let say for customerId = cust123).</p>
  <p>I defined following function in repository.</p>
  <pre><code>public interface TranscationRepository extends MongoRepository&lt;Transaction, String&gt; {
      Optional&lt;Transaction&gt; findTopByCustomerIdOrderByIdDesc(String id);
  }
  </code></pre>
  <p>This method giving last entry not by customerId but overall. I tried few modifications to it but did not get success.</p>
  <p>I know I can findAllByCustomer but I don't want to pull huge list of transaction which is of no use in this use case. What is correct signature in spring mongo to get last inserted record by a field? I am ok to use custom @Query also.
  Thank you.</p>