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;}