I use @Query
annotation and crudRepository to fetch data from MongoDB.
Example:
@Query("{$query: id: ?0}, $orderby: {dateTime: -1}}")
public List<A> findId(
Integer id, Pageable pageable
);
What do I need to add to my @Query
notation if i want to fetch only first N records of collection, or only top N records of collection? I would like to use dynamic query and dynamic set limit and order (first or top records).
you can append your @Query
with $limit : 10, or rename your method like : find First10ByDateDesc()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With