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

♀尐吖头ヾ 提交于 2019-12-13 03:39:27

问题


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" : "....."
            }
            ...
       ]
}

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


回答1:


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.

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.



来源:https://stackoverflow.com/questions/54319790/can-we-use-spring-data-repository-to-update-embedded-documents-in-mongodb

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