Search code examples

How to make a query for mongodb using spring to return objects ordered alphabetically'

I have and class cleed UserModel with the name atribute. And i am trying make a method that return the hole users order alphabetically. My method:

@Query("{ 'name' : { $exists: true }}")
Page<UserModel> findAllByNameOrderByNomeAsc(Pageable pageable);

But this does not work. How can i do that?


  • Check your methods name findAllByNameOrderByNomeAsc(Pageable pageable);

    It should be findAllByNameOrderByNameAsc(Pageable pageable);