Returning Mono<UpdateResult> with Reactive MongoDB template

断了今生、忘了曾经 提交于 2019-12-11 05:12:16

问题


I am trying to get an UpdateResult in a reactive way using MongoDB reactive template in Spring Boot.

The problem is that the update part won't execute as I am not subscribing to it, but I don't really know how to do the 2 operations and returning one value with the reactive paradigm.

This is what I am trying:

@GetMapping("\update")
public Mono<UpdateResult> updateTask(@RequestParam(name="taskId") {
    Mono<UpdateResult> updateResult = mongoReactiveTemplate
            .findById(taskId, Task.class)
            .flatmap(object -> mongoReactiveTemplate.updateFirst(Query.query(... the query), new Update().set("something", Task.class)));

    return updateresult;
}

The flatMap updateFirst wont happen as I am not subscribing, but I need to return the UpdateResult, if I subscribe im not sure how to return that value.


回答1:


Controller 'subscribes' the stream, so returning Mono<UpdateResult> is perfectly fine and will work as expected - http client will get the serialized update result.



来源:https://stackoverflow.com/questions/57019089/returning-monoupdateresult-with-reactive-mongodb-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!