Neo4j批量更新数据

问题描述 投票:0回答:2

如何在 neo4j cypher 中进行多个节点更新?

现在我正在尝试这样做:

MATCH (user151325288158:User{userId:151325288158}),
      (user88245:User{userId:88245}) 
SET user151325288158.balance=2902833.4219789803 
SET user88245.balance=146701.0299999991 
RETURN user151325288158.balance,user88245.balance;

但是这里我有一个问题,如果数据库中不存在这样的用户,则没有人会被更新。 另一个问题是性能,这样的查询很慢。

有什么方法可以进行这样的批量更新吗?

neo4j
2个回答
5
投票

假设您在地图/字典数组中有成对的

userId
和新的
balance
值,如下所示:

[
    {
      "userId": 151325288158,
      "balance": 146701.09
    },
    {
      "userId": 887436512344,
      "balance": 22453.34
    },
    {
      "userId": 873927654232,
      "balance": 300002.22
    }
]

您可以将此数组作为参数传递给

MATCH
上的 Cypher 查询,并更新
userId
属性,如下所示:

balance



2
投票
William Lyon

answer,我能够实现多个属性的批量更新,如下所示: WITH {data} AS pairs UNWIND pairs AS p MATCH (u:User) WHERE u.userId = p.userId SET u.balance = p.balance

© www.soinside.com 2019 - 2024. All rights reserved.