我们可以使用spring数据存储库更新mongodb中的嵌入式文档吗 [英] Can we use spring data repository to update embedded documents in mongodb

查看:31
本文介绍了我们可以使用spring数据存储库更新mongodb中的嵌入式文档吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以使用spring数据存储库更新mongodb中的嵌入文档吗

Can we use spring data repository to update embedded documents in mongodb

    {
    "_id" : 1000,
    "user_id" : "001",
    "events" : [
            {
                    "handled" : 1,
                    "profile" : 10,
                    "data" : "....."
            }
            {
                    "handled" : 1,
                    "profile" : 10,
                    "data" : "....."
            }
            {
                    "handled" : 1,
                    "profile" : 20,
                    "data" : "....."
            }
            ...
       ]
}

我想将句柄更新为 10,其中 events.profile 为 10.我知道如何使用 mongoTemplate 但我需要知道如何使用 mongoRepository.谢谢

I want to update the handle to 10 where events.profile is 10. I know how to do it using mongoTemplate but i need to know how to do it using mongoRepository. Thanks

推荐答案

据我所知,您想创建一个带有更新方法的存储库?在我对 spring-data 参考的研究期间,我找不到任何提示,即 spring 数据支持这一点.

As far as I understand you want to create a Repository with an update-Method? During my resarch in the spring-data reference i couldnt find any hint, that this is supported by spring data.

因此,在您的情况下,您可以创建一个类似Collection findByEvents_Profile(Integer id)"的查询,遍历集合并通过调用存储库的saveAll"方法将其再次持久化.

So in your case you could create a query like 'Collection findByEvents_Profile(Integer id)', iterate over the collection and persist it again by calling the repositories 'saveAll' method.

这篇关于我们可以使用spring数据存储库更新mongodb中的嵌入式文档吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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