Mishamba
Mishamba

Reputation: 29

Spring Data Mongodb @Query with pagination

Is there any way to write some query to mongo with @Query annotation and add paginaiton right into it. I have a method in repository

@Query("{'customer._id' : ?0 }")
List<Order> findOrderByCustomerName(String customerName);

and i want it to looks smth like this

@Query("{'customer._id' : ?0 }.skip{(?1 - 1) * ?2}.limit(?2)")
List<Order> findOrderByCustomerName(String customerName, int page, int size);

Is there any way to to it?

Upvotes: 0

Views: 1430

Answers (1)

Saljack
Saljack

Reputation: 2352

You can add Pageable as a parameter.

@Query("{'customer._id' : ?0 }")
List<Order> findOrderByCustomerName(String customerName, Pageable pageable);

Upvotes: 2

Related Questions