sql >> Base de Datos >  >> NoSQL >> MongoDB

Cómo agregar orderby usando @query en el repositorio mongodb

Puedes hacer como:

@Query("{$and: [ { 'categoryId': { $eq: ?0 } }, { 'isDeleted': { $eq: ?1 } } ]}")
public List<Stage> findByCategoryIdAndIsNotDeleted(String categoryId, Boolean deleted,org.springframework.data.domain.Sort sort);

Y cuando llame a este método, cree el objeto Ordenar como se muestra a continuación:

Sort sort = new Sort(Direction.ASC/DESC,"order");