如何在 neo4j 中为关系添加属性?

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

我使用此代码使用纬度和经度获取两点之间的距离,我想使用此返回值作为两个节点(酒店和我)之间的关系属性 代码:///////

MATCH (u:me)-[d:distance]->(n:Hotels)
WITH
  point({longitude: u.longitude, latitude: u.latitude}) AS trainPoint,
  point({longitude: n.longitude, latitude: n.latitude}) AS officePoint            
RETURN round(point.distance(trainPoint, officePoint)) AS travelDistance

我想将返回值添加到关系距离

python neo4j bigdata spring-data-neo4j
1个回答
0
投票

您可以使用 SET 将属性添加到关系(或节点)。看这里:https://neo4j.com/docs/cypher-manual/current/clauses/set/

举个例子:

MATCH (u:me)-[d:distance]->(n:Hotels)
WITH d,
  point({longitude: u.longitude, latitude: u.latitude}) AS trainPoint,
  point({longitude: n.longitude, latitude: n.latitude}) AS officePoint            
WITH d, round(point.distance(trainPoint, officePoint)) AS travelDistance
SET d.travelDistance = travelDistance
RETURN d
© www.soinside.com 2019 - 2024. All rights reserved.