[英]MongoRepository findAll() returns empty list
findAll() of mongoRepository returns empty list. mongoRepository 的 findAll() 返回空列表。 what is wrong with the below code?
下面的代码有什么问题? API used for counting the number of documents in the collection works fine.
API 用于计算集合中的文档数量工作正常。
Controller 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 model如下
@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.
为了 findAll() 工作,model 必须具有已删除状态。
I've updated the model as follows我已经更新了 model 如下
@Data
@Document("auth-scopes")
public class AuthScope {
@Id
private String scope;
private String belongsToApi;
private String belongsToApiTitle;
private String description;
private boolean deleted;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.