Neo4j批量更新数据
如何在neo4j cypher中更新多个节点 现在我试着这样做:Neo4j批量更新数据,neo4j,Neo4j,如何在neo4j cypher中更新多个节点 现在我试着这样做: MATCH (user151325288158:User{userId:151325288158}), (user88245:User{userId:88245}) SET user151325288158.balance=2902833.4219789803 SET user88245.balance=146701.0299999991 RETURN user151325288158.balance,user8
MATCH (user151325288158:User{userId:151325288158}),
(user88245:User{userId:88245})
SET user151325288158.balance=2902833.4219789803
SET user88245.balance=146701.0299999991
RETURN user151325288158.balance,user88245.balance;
[
{
"userId": 151325288158,
"balance": 146701.09
},
{
"userId": 887436512344,
"balance": 22453.34
},
{
"userId": 873927654232,
"balance": 300002.22
}
]
WITH {data} AS pairs
UNWIND pairs AS p
MATCH (u:User) WHERE u.userId = p.userId
SET u.balance = p.balance
但在这里我有一个问题,若这样的用户在数据库中不存在,并没有人会被更新。
另一个问题是性能,这样的查询速度很慢
是否有一些方法可以进行此类批量更新?假设您在地图/目录数组中有成对的
userId
s和新的balance
值,如下所示:
MATCH (user151325288158:User{userId:151325288158}),
(user88245:User{userId:88245})
SET user151325288158.balance=2902833.4219789803
SET user88245.balance=146701.0299999991
RETURN user151325288158.balance,user88245.balance;
[
{
"userId": 151325288158,
"balance": 146701.09
},
{
"userId": 887436512344,
"balance": 22453.34
},
{
"userId": 873927654232,
"balance": 300002.22
}
]
WITH {data} AS pairs
UNWIND pairs AS p
MATCH (u:User) WHERE u.userId = p.userId
SET u.balance = p.balance
您可以将此数组作为参数传递给密码查询,以在userId
上MATCH
,并更新balance
属性,如下所示:
MATCH (user151325288158:User{userId:151325288158}),
(user88245:User{userId:88245})
SET user151325288158.balance=2902833.4219789803
SET user88245.balance=146701.0299999991
RETURN user151325288158.balance,user88245.balance;
[
{
"userId": 151325288158,
"balance": 146701.09
},
{
"userId": 887436512344,
"balance": 22453.34
},
{
"userId": 873927654232,
"balance": 300002.22
}
]
WITH {data} AS pairs
UNWIND pairs AS p
MATCH (u:User) WHERE u.userId = p.userId
SET u.balance = p.balance
假设在一组映射/目录中有成对的
userId
s和新的balance
值,如下所示:
MATCH (user151325288158:User{userId:151325288158}),
(user88245:User{userId:88245})
SET user151325288158.balance=2902833.4219789803
SET user88245.balance=146701.0299999991
RETURN user151325288158.balance,user88245.balance;
[
{
"userId": 151325288158,
"balance": 146701.09
},
{
"userId": 887436512344,
"balance": 22453.34
},
{
"userId": 873927654232,
"balance": 300002.22
}
]
WITH {data} AS pairs
UNWIND pairs AS p
MATCH (u:User) WHERE u.userId = p.userId
SET u.balance = p.balance
您可以将此数组作为参数传递给密码查询,以在userId
上MATCH
,并更新balance
属性,如下所示:
MATCH (user151325288158:User{userId:151325288158}),
(user88245:User{userId:88245})
SET user151325288158.balance=2902833.4219789803
SET user88245.balance=146701.0299999991
RETURN user151325288158.balance,user88245.balance;
[
{
"userId": 151325288158,
"balance": 146701.09
},
{
"userId": 887436512344,
"balance": 22453.34
},
{
"userId": 873927654232,
"balance": 300002.22
}
]
WITH {data} AS pairs
UNWIND pairs AS p
MATCH (u:User) WHERE u.userId = p.userId
SET u.balance = p.balance
通过以下步骤,我能够实现多个属性的批更新,如下所示:
UNWIND [{id: 123456, name: "John", age: 27}, {id: 789012, name: "Jane", age: 24}] AS updateUser
MATCH (user: User)
WHERE user.id = updateUser.id
SET user += updateUser
RETURN user
通过以下步骤,我能够实现多个属性的批更新,如下所示:
UNWIND [{id: 123456, name: "John", age: 27}, {id: 789012, name: "Jane", age: 24}] AS updateUser
MATCH (user: User)
WHERE user.id = updateUser.id
SET user += updateUser
RETURN user