如何在neo4j中返回节点之前添加属性

时间:2019-05-16 16:12:24

标签: neo4j neo4j-ogm

我需要返回一个集合作为节点的属性。我有一个人员节点,该节点可以与另一个人建立多种关系。

enter image description here

我需要返回跟随一个人A的所有人,并将他们之间的所有关系作为属性返回,

这是查询:

match (a: Person {email:' a@email.com '}) <- [: FOLLOW] - (x: Person)
with a, x
match (a) - [r] - (x) 
return x, collect (type (r)) as relations; 

我需要向人x添加集合'关系'作为节点'x'的属性

与此处说明的相反:'https://neo4j.com/developer/kb/updating-a-node-but-returning-its-state-from-before-the-update/',在这种情况下,他们返回快照,但是在更新节点之前,我真正需要的是在不实际更新快照的情况下修改快照。节点,我正在尝试:

match(a:Person{email:'a@email.com'})<-[:FOLLOW]-(x:Person) 
with a,x
match(a)-[r]-(x)
with properties(x) as snapshot, collect(type(r)) as relations;
set snapshot.relations = relations
RETURN snapshot

但是当我这样做时,出现了以下错误:每个查询只需要一条语句,但得到了:2

更新:还说@ krishna-reddy消除了“;”修复了上述错误,但现在显示了此错误: Neo.ClientError.Statement.SyntaxError:类型不匹配:预期的节点或关系,但是是Map

2 个答案:

答案 0 :(得分:1)

match(a:Person{email:'a@email.com'})<-[:FOLLOW]-(x:Person) 
with a,x
match(a)-[r]-(x)
with properties(x) as snapshot, collect(type(r)) as relations
set snapshot.relations = relations
RETURN snapshot

只需删除;在第4行中。

答案 1 :(得分:1)

您可以使用APOC plugin,它具有创建Virtual Nodes and Relationships的过程,这些过程没有存储在数据库中。

图形中不存在虚拟节点和关系,它们仅返回给UI /用户以表示图形投影。可以将它们可视化或进行其他处理。

MATCH(a:Person{email:'a@email.com'})<-[:FOLLOW]-(x:Person) 
WITH a,x
MATCH(a)-[r]-(x)
WITH x, collect(type(r)) AS relations
CALL apoc.create.vNode([head(labels(x))], x{.*,relations:relations}) YIELD node AS snapshot
RETURN snapshot