Reactor,布尔值返回对象
Reactor, Boolean by value Returned object
我想根据模型名称创建一个新的集合。如果存在同名集合,则返回现有集合。如果没有,新创建的集合returns。我正在使用 ReactiveCrudRepository。我是反应新手。我在底层代码中收到此错误。我该怎么办?
public Mono<MongoCollection<Document>> constructDBCollection(String modelName) {
return reactiveMongoOperations.collectionExists(modelName)
.flatMap(exists -> exists ? reactiveMongoOperations.getCollection(modelName) : reactiveMongoOperations.createCollection(modelName, CollectionOptions.empty()
.size(1024 * 1024)
.capped()));
}
Error The type of flatMap(java.util.function.Function>) is
erroneous DBCollectionFactory.java /src/main/java/com/jagger/obls/factory/DBCollectionFactory.java:26
Error incompatible types: cannot infer type-variable(s) R
(argument mismatch; bad return type in lambda expression bad
type in conditional expression
com.mongodb.reactivestreams.client.MongoCollection
cannot be converted to reactor.core.publisher.Mono) DBCollectionFactory.java /src/main/java/com/jagger/obls/factory/DBCollectionFactory.java:26
根据 javadoc,getCollection
实际上是 returns MongoCollection<Document>
,而不是它的 Mono
。因此,将此调用包装在 Mono.just(reactiveMongoOperations.getCollection(modelName))
中应该可以做到。
我想根据模型名称创建一个新的集合。如果存在同名集合,则返回现有集合。如果没有,新创建的集合returns。我正在使用 ReactiveCrudRepository。我是反应新手。我在底层代码中收到此错误。我该怎么办?
public Mono<MongoCollection<Document>> constructDBCollection(String modelName) {
return reactiveMongoOperations.collectionExists(modelName)
.flatMap(exists -> exists ? reactiveMongoOperations.getCollection(modelName) : reactiveMongoOperations.createCollection(modelName, CollectionOptions.empty()
.size(1024 * 1024)
.capped()));
}
Error The type of flatMap(java.util.function.Function>) is erroneous DBCollectionFactory.java /src/main/java/com/jagger/obls/factory/DBCollectionFactory.java:26
Error incompatible types: cannot infer type-variable(s) R
(argument mismatch; bad return type in lambda expression bad type in conditional expression
com.mongodb.reactivestreams.client.MongoCollection cannot be converted to reactor.core.publisher.Mono) DBCollectionFactory.java /src/main/java/com/jagger/obls/factory/DBCollectionFactory.java:26
根据 javadoc,getCollection
实际上是 returns MongoCollection<Document>
,而不是它的 Mono
。因此,将此调用包装在 Mono.just(reactiveMongoOperations.getCollection(modelName))
中应该可以做到。