Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3643

Springboot MongoRepository findAll() method returns an empty list, But other Methods return valid results

$
0
0

findAll() method of mongoRepository returns an empty list. what is wrong with the below code?API used for counting the number of documents in the collection works fine and because of that, findAll() also should return a valid result.

Controller

@RestController@RequestMapping("/api/api-management/scopes")public class AuthScopesController {    private final ScopesService scopesService;    @Autowired    AuthScopesController(ScopesService scopesService) {        this.scopesService = scopesService;    }    @PostMapping("/")    public AuthScope createScope(@RequestBody AuthScope authScope) {        return scopesService.createAuthScope(authScope);    }    @GetMapping("/")    public List<AuthScope> getAllScopes() {        return scopesService.getAuthScopes();    }}

service

@Servicepublic class ScopesService {    private final AuthScopeRepository authScopeRepository;    public ScopesService(AuthScopeRepository authScopeRepository) {        this.authScopeRepository = authScopeRepository;    }    public AuthScope createAuthScope(AuthScope authScope) {        return authScopeRepository.save(authScope);    }    //TODO: recheck    public List<AuthScope> getAuthScopes() {        return authScopeRepository.findAll();    }}

repository

@Repositorypublic interface AuthScopeRepository extends MongoRepository<AuthScope, String> {    Optional<AuthScope> findByScope(String id);}

model is as follows

@Data@Document("auth-scopes")public class AuthScope  {    @Id    private String scope;    private String belongsToApi;    private String belongsToApiTitle;    private String description;}

Viewing all articles
Browse latest Browse all 3643

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>