我正在扫描目录中的文件,然后处理结果。我想在进一步处理之前从数据存储中已有的扫描结果中删除文件。
尝试使用响应式 mongodb 以响应式方式执行此操作。我只是不确定如何以使用数据库查询结果的方式实现过滤器。
@Override
public Flux<File> findFiles(Directory directory) {
// Only get these file types as we can't process anything else
final Predicate<Path> extensions = path ->
path.toString().endsWith(".txt") ||
path.toString().endsWith(".doc") ||
path.toString().endsWith(".pdf");
final Set<File> files = fileService.findAll(Paths.get(directory.getPath()), extensions);
final Stream<Video> fileStream = files
.stream()
.map(this::convertFileToDocument)
// This is wrong (doesn't compile for a start), but how do I do something similar or of this nature?
.filter(file -> fileRepository.findById(file.getId()));
return Flux.fromStream(fileStream);
}
convertFileToDocument
只是将文件映射到 POJO,那里没有发生任何有趣的事情。
如何根据 的结果添加过滤器findById
,或者有更好的方法来实现这一点?