从我的搜索中我没有找到一种方法来动态设置对象的属性,只是通过定义硬编码(如“详细”属性下面)
这是我的样本: Neo4j Graph或通过Neo4j Console
MATCH(p:Person)-[r]->(m:Movie)
WITH { Person: p.name,
Detail: collect(r.roles)
} AS Result
RETURN Result
我的目标(尚未开始):
MATCH(p:Person)-[r]->(m:Movie)
WITH { Person: p.name,
CASTED_FOR: // --> Only values(r.roles) for relationship "CASTED_FOR" needed here
ACTED_IN: // --> Only values(r.roles) for relationship "ACTED_IN" needed here
} AS Result
RETURN Result
我知道我可以[r:CASTED_FOR]或WHERE Type(r)=“CASTED_FOR”,但我不喜欢有多个WITH和MATCH查询。
谢谢
答案 0 :(得分:3)
此查询使用Cypher的list comprehension构造来执行您想要的操作:
MATCH (p:Person)-[r]->(:Movie)
WITH p, COLLECT(r) AS rs
RETURN {
Person: p.name,
CASTED_FOR: [x IN rs WHERE TYPE(x) = 'CASTED_FOR' | x.roles],
ACTED_IN: [x IN rs WHERE TYPE(x) = 'ACTED_IN' | x.roles]
} AS Result