Neo4j确定最近的节点,该节点的子节点少于两个

Neo4j确定最近的节点,该节点的子节点少于两个,neo4j,spring-data-neo4j,Neo4j,Spring Data Neo4j,有人能帮我解决问题吗?假设我有一个二叉树,我应该按照以下规则在其中附加子元素: 树中给定的随机节点 在最近的可用位置,节点应被视为给定节点的子节点,作为节点的直接子节点,该节点有leess和2个子节点 我陷入了对实际父节点的密码查询无法正常工作的困境 我现在拥有的是 start n=node({0}) match child-[B_PARENT]->n OPTIONAL MATCH child<-[r:B_PARENT]-() WITH count(r) as c, child

有人能帮我解决问题吗?假设我有一个二叉树,我应该按照以下规则在其中附加子元素:

树中给定的随机节点 在最近的可用位置,节点应被视为给定节点的子节点,作为节点的直接子节点,该节点有leess和2个子节点 我陷入了对实际父节点的密码查询无法正常工作的困境

我现在拥有的是

start n=node({0}) 
match child-[B_PARENT]->n 
OPTIONAL MATCH child<-[r:B_PARENT]-() 
WITH count(r) as c, child WHERE c < 2 
return child ORDER BY id(child) LIMIT 1
这里的逻辑是假设给定的节点在二叉树中,它最多有3个关系。如果根节点是根节点,则它最多有2个关系

(node1 <> node2 AND node1 = n AND count(r)<2)  // will work only for root node

(node1 <> node2 AND node1 <> n AND count(r)<3) //will work for other nodes in the tree

因此,上面的查询应该返回一个节点,该节点为id最少的子节点打开了一个位置。

也许您可以使用创建和共享一个小样本数据集?
(node1 <> node2 AND node1 = n AND count(r)<2)  // will work only for root node

(node1 <> node2 AND node1 <> n AND count(r)<3) //will work for other nodes in the tree