Can we use spring data repository to update embedd

2019-08-23 04:06发布

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条回答
唯我独甜
2楼-- · 2019-08-23 04:32

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.

查看更多
登录 后发表回答