Spring Boot Neo4j 部分更新操作

huangapple go评论78阅读模式
英文:

Spring Boot Neo4j partial update operation

问题

更新Spring Boot应用程序中的Neo4j数据库中的节点的最聪明方法是什么。

我会收到一个像这样的对象:

{
    "name":"name",
    "surname":"surname",
    "likes":[
        {
            "name":"football",
            "score":9
        },
        {
            "name":"golf",
            "score":6
        }
    ]
}

我想使用同样的对象,但只选择一些值,例如:

{
    "surname":"otherSurname"
}

并实现以下效果:

{
    "name":"name",
    "surname":"otherSurname",
    "likes":[
        {
            "name":"football",
            "score":9
        },
        {
            "name":"golf",
            "score":6
        }
    ]
}

或者添加一些内容到列表中:

"likes": [
        {
            "name": "basketball",
            "score": 7
        }
    ]

有没有办法做到这一点?

起初,我尝试删除节点并保存一个新节点,但每次我都没有获得整个对象。

英文:

What is the smartest way to update nodes partially in Spring Boot application with Neo4j db.

I will get an object like this:

{
    "name":"name",
    "surname":"surname",
    "likes":[
        {
            "name":"football",
            "score":9
        },
        {
            "name":"golf",
            "score":6
        }
    ]
}

I would like to use same object but with some choosen values for example:

{
    "surname":"otherSurname"
}
 

and achive something like this:

{
    "name":"name",
    "surname":"otherSurname",
    "likes":[
        {
            "name":"football",
            "score":9
        },
        {
            "name":"golf",
            "score":6
        }
    ]
}

Or add something to list:

"likes": [
        {
            "name": "basketball",
            "score": 7
        }
    ]

Is any way to do this?

At first I tried to delete the node and save a new one, but each time I don't get the whole object

答案1

得分: 0

如果您不首先删除节点,而是重新保存整个对象,它应该会更新新的值并添加/删除数据库中没有的内容。

如果您只想选择某些属性保存在对象或领域类中,我会编写一个自定义查询,仅设置更新/新值,然后保留其他部分。

我正在为这种情况制作一些示例,但目前还没有可以演示的内容。

英文:

If you don't delete the node first and, instead, re-save the whole object, it should update new values and add/remove things that aren't in the database.

If you only want to pick and choose certain properties to save out of an object or domain class, I would write a custom query to set the updated/new values only and leave the rest.

I'm working on some examples for scenarios like this, but I don't have anything to send for demonstrating just yet.

huangapple
  • 本文由 发表于 2023年6月29日 00:35:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76575131.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定