How to add orderby using @query in mongodb repository
I want to add orderby to the following repository method in mongodb with spring. I tried in various methods, but didnt work public interface StageRepository extends MongoRepository<Stage, String> { @Query("{$and: [ { 'categoryId': { $eq: ?0 } }, { 'isDeleted': { $eq: ?1 } } ]}") public List<Stage> findByCategoryIdAndIsNotDeleted(String categoryId, Boolean deleted); } I want to add orderby 'order' in the query. Not sure how to do it. Viresh You can do like : @Query("{$and: [ { 'categoryId': { $eq: ?0 } }, { 'isDeleted': { $eq: ?1 } } ]}") public List<Stage> findByCategoryIdAndIsNotDeleted