Neo4j - 查找具有超过 X children 类型 B 的类型 A 节点

Neo4j - find nodes of type A which have more than X children of type B

我想找到所有超过 X children 个 B 类型的 A 类型节点。

child我的意思是这个节点通过任何方向的任何关系连接到其他节点。

我的查询 returns 结果,但这不是我所期望的:

MATCH (Parent:typeA)-[R]-(Child:typeB)
WITH Parent, Child, count(R) as ChildCount
WHERE ChildCount > 3
RETURN Parent, Child, ChildCount

它通常 returns 带有 ChildCount=1 的东西,我可以手动查询这些东西并检查它们是否有更多 children 这种类型。

这 returns Parent 个节点有 > 3 Child 个节点通过 R

相关
MATCH (Parent:typeA)
WHERE SIZE([(Parent)-[R]-(Child:typeB) | Child]) > 3
RETURN Parent

或者这个,如果你需要 children

MATCH (Parent:typeA)-[R]-(Child:typeB)
WITH Parent, COLLECT(Child) AS children
WHERE SIZE(children) > 3
RETURN Parent,children