'How to use limit and skip in spring data mongodb repository?

I want query sublist in mongo collections using Spring Data MongoDB. My Code is like

public interface SomeRepo extends MongoRepository<SomeDoc, String> {
    @Query("{'field0': ?0, 'field1': ?1}, {'limit':?2, 'skip':?3}")
    List<SomeDoc> findAllByField0AndFiled1(
        Long field0,
        Long field1,
        Long limit,
        Long skip
    );
}

but limit & skip are not in Query Object

Log is Created query Document{{field0=123, field1=456}} for Document{{}} fields.

how to pass them into query object?



Solution 1:[1]

Thanks to @prasad_ for the answer. Using @Aggregation can solve my question.

@Aggregation("{'field0': ?0, 'field1': ?1}, {limit': ?2, 'skip': ?3}")
    List<SomeDoc> findAllByField0AndFiled1(
        Long field0,
        Long field1,
        Long limit,
        Long skip
    );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1