简体   繁体   English

在 Spring Data Mongodb Reactive 中执行顺序查询

[英]Execute sequencial queries in Spring Data Mongodb Reactive

I have to found All documents in collection B not referenced in collection A.我必须找到集合 B 中未在集合 A 中引用的所有文档。

Using the method in ReactiveMongoRepository使用 ReactiveMongoRepository 中的方法

Flux<A> findAll();

So I made this code:所以我做了这个代码:

collectionARepository.findAll()
    .flatMap(d -> d.documentBID())
    .collectList()
    .flatMap(list -> collectionBRepository.findDocsNotIn(list))
    .flatMap(b -> log.info(b.id())
    .subscribe();

But, if there's no documents in collection A, the second query will not be executed.但是,如果集合 A 中没有文档,则不会执行第二个查询。 How can I force the execution of second to get all documents.如何强制执行 second 以获取所有文件。

Found the solution.找到了解决办法。

My IDE for some reason was not show error, but When I use collectList I passed from Flux to Mono.由于某种原因,我的 IDE 没有显示错误,但是当我使用collectList我从 Flux 传递到 Mono。 When I call flatMap (It should show an error) I cannot return a Flux, only a Mono.当我调用 flatMap (它应该显示错误)时,我无法返回 Flux,只能返回 Mono。 That causes an Exception and It was treat like "Entity not found".这会导致异常,并且被视为“未找到实体”。 My bad.我的错。

So here is my final code:所以这是我的最终代码:

collectionARepository.findAll()
    .flatMap(d -> d.documentBID())
    .collectList()
    .flatMapMany(list -> collectionBRepository.findDocsNotIn(list))
    .flatMap(b -> log.info(b.id())
    .subscribe();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RSocket适用于生成的数据,但不适用于Spring Reactive MongoDB - RSocket works with generated data but not with Spring Reactive MongoDB Spring WebFlux:Spring Data Reactive MongoDB中的block()方法返回null - Spring WebFlux: block() method return null in Spring Data Reactive MongoDB MongoDB的Spring数据中的非阻塞查询? - Non-blocking Queries in Spring Data for MongoDB? 创建多个MongoDB查询的Spring Data Aggregation - Creating Spring Data Aggregation of multiple MongoDB queries 响应式Spring Data Mongodb查询在不应该返回旧数据的情况下 - Reactive Spring Data Mongodb Query is returning old data when it should not 如何使用Spring data-mongodb-reactive从受限制的集合中流式传输 - How to stream from a capped collection with Spring data-mongodb-reactive 如何将数据库引用与反应式 Spring Data MongoDB 一起使用? - How to use db references with reactive Spring Data MongoDB? 等待无功更改 ZF7B44CFFAFD5C52223D5498196C8A2E7BZ 订阅激活 Spring 数据 MongoDB? - Wait for reactive change stream subscription to be active with Spring Data MongoDB? 更新 1 个或多个特定字段 MongoDB 使用 Spring 启动 WebFlux,Spring 数据 Z206E3718AF0921CC1D12F80ZReposit7 - Update 1 or multiple specific field MongoDB using Spring boot WebFlux,Spring Data MongoDB Reactive and ReactiveMongoRepository Spring Reactive MongoDB连接到MongoDB云 - Spring Reactive MongoDB connected to MongoDB cloud
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM