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

how to add an attribute before returning the node in neo4j

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

我需要return所有关注一个人A的人和return他们之间的所有关系作为一个属性,

这是查询:

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,集合'relations'作为节点的属性'x'

这与这里解释的正好相反:'https://neo4j.com/developer/kb/updating-a-node-but-returning-its-state-from-before-the-update/',在这种情况下,他们return一个快照但是在他们更新节点之前,我真正需要的是修改没有实际更新节点的快照,我正在尝试:

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

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 行。

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

图中不存在虚拟节点和关系,它们仅返回到 UI/user 以表示图投影。它们可以被可视化或以其他方式处理。

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