3

在 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 中做同样的事情。

4

1 回答 1

3

不确定这是否可行,而且我目前没有运行 1.9,但它过去一直这样工作。

START n=node(2)
MATCH (n)-->(m)
WHERE length((m)-->()) = 1
RETURN m
于 2014-06-10T15:56:48.077 回答