在 neo4j 1.9.7 中,有什么方法可以进行仅返回基数为 1 的传出关系的密码查询?
例如
N2 ----> N4 -----> N10
| |-------> N9
|
|------> N5 -----> N9
|
|------> N6 -----> N9
在这样的结构中,我想遍历节点并仅返回只有一个传出关系的节点(示例中为 N5 和 N6)。
我可以使用 Java API 使用 IteratorUtil 类来获取计数
Node process = db.getNodeById(2);
for(Relationship rel : process.getRelationships(Direction.OUTGOING))
{
Node appProcess = rel.getOtherNode(process);
if(IteratorUtil.count(appProcess.getRelationships(Direction.OUTGOING).iterator()) == 1)
{
System.out.println(appProcess.getId()+" is a vital process");
count++;
}
}
我想在 Cypher 中做同样的事情。