findAll() of mongoRepository returns empty list. what is wrong with the below code? API used for counting the number of documents in the collection works fine.
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
@Service
public 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
@Repository
public 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;
}
found the issue. in order to findAll() to work, the model has to have deleted status.
I've updated the model as follows
@Data
@Document("auth-scopes")
public class AuthScope {
@Id
private String scope;
private String belongsToApi;
private String belongsToApiTitle;
private String description;
private boolean deleted;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.