2017-11-11 254 views
0

我使用此代码获得节点ab之间包含两个或更少关系的路径RTNeo4j。创建约束来计算具有类型“RT”的关系?

MATCH (a:Tes1 { title: "a" }),(b:Tes1 { title: "b" }), p=shortestPath((a)-[r:BT|RT*]-(b)) 
WITH count(type(r)='RT') as cnt 
WHERE cnt < 3 
RETURN p; 

错误:

Type mismatch: expected Relationship but was List (line 2, column 17 (offset: 111)) "WITH count(type(r)='RT') as cnt"

我知道这个错误的手段,但我不知道另一种方式。 请帮助

回答

1

你不能指望一个特定类型的集合,需要对其进行过滤,并得到其大小:

MATCH (a:Tes1 { title: "a" }),(b:Tes1 { title: "b" }), p=shortestPath((a)-[r:BT|RT*]-(b)) 
WITH p, filter(x IN relationships(p) WHERE type(x) = "RT") AS rtRels 
WHERE size(rtRels) < 3 
RETURN p;