返回Mono< UpdateResult>.使用反应式MongoDB模板 [英] Returning Mono<UpdateResult> with Reactive MongoDB template

查看:1181
本文介绍了返回Mono< UpdateResult>.使用反应式MongoDB模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Spring Boot中的MongoDB反应性模板以反应性方式获取UpdateResult.

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

问题在于更新部分将不会执行,因为我没有订阅它,但是我真的不知道如何执行2个操作并使用反应性范式返回一个值.

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.

这是我正在尝试的:

@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;
}

flatMap updateFirst不会发生,因为我没有订阅,但是如果我不确定如何返回该值,则需要返回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.

推荐答案

控制器订阅"流,因此返回Mono<UpdateResult>非常好,并且可以按预期工作-HTTP客户端将获得序列化的更新结果.

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

这篇关于返回Mono&lt; UpdateResult&gt;.使用反应式MongoDB模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆